Friday, February 25, 2011

Running a Powershell script in Vista/Windows 7 without prompting for elevation or security

Some time ago I needed to share a very simple PowerShell script with a user for a one-time execution.  Before I forget it I wanted to write it down.

At the time I didn't have the capability to sign the script but I didn't want to complicate things for the user by asking them to run an elevated prompt and re-configure PowerShell's execution policy for remote-signed code.  I looked around for a workaround and this is what I found.

First, the guys at Wintellect developed a simple workaround for elevation in the command shell for Vista or Windows 7.  Get a copy here:

Next, powershell has a command line option to bypass the execution policy.

Combining the two together in a batch file delivers a simple way to accomplish my objective:

elevate powershell.exe -nologo -noprofile -windowstyle hidden -command "& {set-executionpolicy Bypass -scope Process; .\myscript.ps1}"

No comments:

Post a Comment