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?
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:
One way to do it is to create a batch file with the appropriate commands.
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "& 'c:\scripts\build_project.ps1' "
You will have to pass commandline arguments from the batch file to the script if your ps script uses them. You will also have to load all the powershell modules your script uses: