Powershell – way to register python scripts to run “by themselves” under PowerShell

powershellpython

This question nicely covers getting python scripts running under CMD.EXE without having to type a bunch of extra stuff – that is "> script" rather than "> python script.py".

However, I can't seem to get the same behavior under PowerShell. Entering "PS > script.py" there just gets me the "is not recognized as a cmdlet, function, operable program, or script file" error.

How do I get PowerShell to recognize the same file associations that CMD does?

Best Answer

Aha, I've found the answer myself.

In PowerShell, scripts to be executed need to be proceeded by ".\"

So, "PS > script.py" doesn't work, but "PS > .\script.py" does.

Also, using this syntax adding ".py" to PATHEXT works fine under PowerShell.