Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
If said file manager is Far, then you can trivially change what runs when pressing enter on a .ps1 file. – Joey Aug 2 '10 at 7:25
up vote 1 down vote accepted

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:

assoc .ps1

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.

ftype Microsoft.PowerShellScript.1="c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe" "& '&1'"

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:

set pathext=.ps1;%pathext%
share|improve this answer
Note that there are good reasons that this is not the default setting. – Joey Aug 2 '10 at 7:25

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:

Add-PSSnapin Module-Name
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.