Monday, November 7, 2011

Associating execution of Powershell scripts with the default open action in Windows 7

I've been using Powershell a bit lately and finally got to the point where I'm using it so much I want to be able to simply double click on a *.ps1 script file and have Powershell execute it.  So, in the interest of creating an internet based reference that I can Google myself when I forget this:


*** Note:  Always backup your registry before editing it unless you really like rebuilding things ***

Basically you need to create a default value inside the registry key (if the sequence of keys doesn't exist, create them):

     HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command

Leave the value with the name '(Default)', make it of type REG_SZ, and set the data to:

     \system32\WindowsPowerShell\v1.0\powershell.exe -command "& '%1' "

Where "" is the location of your Windows directory.


The sequence "& '%1' " is important.

BTW, I highly recommend that you make sure your Powershell script execution settings are set to require remote scripts to be signed properly.

No comments:

Post a Comment