# Powershell and python executables

**URL:** <https://discuss.python.org/t/powershell-and-python-executables/27447>\
**Category:** Python Help\
**Created:** [June 5, 2023, 9:38pm UTC](https://discuss.python.org/t/powershell-and-python-executables/27447 "2023-06-05T21:38:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![datafiend](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/datafiend/32/5167_2.png) [@datafiend](https://discuss.python.org/u/datafiend)\
**Post date:** [June 5, 2023, 9:38pm UTC](https://discuss.python.org/t/powershell-and-python-executables/27447/1 "2023-06-05T21:38:08Z")

</div>

I’m trying to run simple python scripts with PowerShell. I can run my scripts in .cmd without a hitch. The path looks proper. I opened PowerShell in admin mode as well and it’s still not working.  
Researching the web, it seems that MicroSoft disables the functionality of running python with PowerShell?  
I’m on PS 7.2 and python 3.11

Thanks,

---

<div class="post-metadata">

**Author:** ![datafiend](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/datafiend/32/5167_2.png) [@datafiend](https://discuss.python.org/u/datafiend)\
**Post date:** [June 6, 2023, 4:35am UTC](https://discuss.python.org/t/powershell-and-python-executables/27447/2 "2023-06-06T04:35:08Z")

</div>

I solved it. Looks like you need to type python and then the file name. Thanks.

---

<div class="post-metadata">

**Author:** ![moosemaimer](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/moosemaimer/32/15091_2.png) [@moosemaimer](https://discuss.python.org/u/moosemaimer)\
**Post date:** [June 6, 2023, 1:54pm UTC](https://discuss.python.org/t/powershell-and-python-executables/27447/3 "2023-06-06T13:54:34Z")

</div>

You can run scripts (python, powershell, etc) from a PS prompt by using the “.\” syntax, just like “./” from a Linux shell.

```auto
PS C:\pyprograms> .\lanscan2

```

---

<div class="post-metadata">

**Author:** ![eryksun](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/eryksun/32/697_2.png) [@eryksun](https://discuss.python.org/u/eryksun)\
**Post date:** [June 6, 2023, 2:05pm UTC](https://discuss.python.org/t/powershell-and-python-executables/27447/4 "2023-06-06T14:05:54Z")

</div>

If .py files are correctly associated with the “Python.File” progid, then you should be able to run Python scripts directly in the shell if they’re in any directory in the `PATH` environment variable. A script in the current directory (“.”) has to be referenced explicitly, e.g. `.\spam.py`.

PowerShell misuses the `PATHEXT` environment variable, however. In CMD, `PATHEXT` has always been just a list of extensions to try appending when searching `PATH` for a file, and it has nothing to do with how or whether files are allowed to be executed. PowerShell, in contrast, requires a file extension to be in `PATHEXT` in order to execute the file type normally in the current console session. So make sure that “.PY” is included in `PATHEXT`.
