I have a PowerShell script for building my project files, and I'd like to have capability to run it from my file manager's command line (and, possibly, make a shortcut to this script so I can start build from my desktop)
Any way to do this?
Windows – How to launch PowerShell script from the OS command line
command-line-interfacepowershellwindows
Related Topic
- PowerShell script, showing commands run
- Windows – How to run a PowerShell script from Cygwin SSH session
- PowerShell script works from command line, not from Task Scheduler. Why
- Windows – How to create a scheduled task from the command line that only runs on demand
- PowerShell Command ‘write-zip’ doesn’t work
Best Answer
If you want to make powershell scripts behave a little more like typical cmd\bat scripts where you can just type the name and have them execute you can set up the association and file type to tell the shell to pass the correct parameters to Powershell and set the patheext variable so you just have to type the name of the script rather than the full name.ext.
First check that the .ps1 extension is associated with Powershell - it should be but it's worth making sure:
This should give you something like the following:
Now override the default open behaviour (open with notepad) for this file type with the Powershell commandline syntax for calling a script. We need to add additional quotes around the parameter &1 to handle paths with spaces.
If you really want Powershell scripts to act like other script files then modify the pathext environment variable. Ideally set this in via My Computer->Properties->Advanced System Settings->Advanced tab->Environment Variables but you can temporarily set this in a cmd shell via: