After adjusting the PATHEXT
and PATH
environment variables, PowerShell scripts can accessed from the Command Prompt. The issue comes, however, is that when attempting to execute a script (ie, CMD> foobar
where foobar.ps1
is on the path) Notepad opens the script instead of Powershell being invoked to execute the script.
The goal is to be able to run CMD> foobar
and invoke the PowerShell script and return the results directly into the console.
Here are a few solutions to the problem that somewhat come close to, but don't, meet the needs:
- Setting the Execution Policy to a more permissive setting
- While this helps, it doesn't let me run the
.ps1
s directly from the CMD command line.
- While this helps, it doesn't let me run the
- Opening the PowerShell prompt and running the script
- This kind of defeats the purpose. While I am shifting to a PowerShell-first mindset, I need solutions in the interim.
- Setting registry keys to double click the script
- This helps somewhat, but I don't think it actually does anything for this problem.
- Prefixing the command with
powershell -File
- This doesn't solve the problem because I want to
CMD> foobar
, notCMD> powershell -File foobar
.
- This doesn't solve the problem because I want to