SiKing

January 26, 2010

How to fix Windows Powershell?

Filed under: windows — SiKing @ 2:06 pm
Tags:

PowerShell icon
I am doing some automation work – it has to run from the command line, and completely unattended. Most recently, I am doing it under Windows. The classic command.com shell has definite limitations, and the next step up is suppose to be the Windows Powershell. As awesome as this scripting shell is </sarcasm>, it unfortunately installs broken by default: you cannot run any scripts. Even though Microsoft calls this a security feature it makes the scripting shell rather useless. The procedure to unbreak it is quite hidden; not to mention written by someone who a) has a very quirky sense of humour, even for a geek, and b) has obviously never heard of Linux or bash.

I will spare you all the (other) bits like:

Most important, you’ll also be able to say things like, “You know, you really ought to dot source that script when you run it.” If that doesn’t impress your colleagues then nothing will.

The (one-time) procedure to unbreak it is:

1. From inside of powershell you need to run:

PS> Set-ExecutionPolicy RemoteSigned

Update: On Vista (and probably later) this will not work – you will get access to modify registry denied. You can either run powershell As Administrator, or you can edit the registry manually:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="RemoteSigned"

2. Then for your .ps1 files, you can associate a Run command:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noexit &'%1'

Yes, it must be single-quotes! 🙄

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: