Please note: This blog is no longer active. My new blog is located at http://blog.timwheeler.io

Wednesday, October 21, 2009

PowerShell Execution Policy

So I decided it was high time I looked into PowerShell and see what all the fuss was about.  Grabbed a script I needed from CodePlex.  Installed PowerShell.  Found the syntax to run the script:  .\myScript.ps1

Great, so I execute it.  And nothing.  It just shows a new line with a flashing cursor.  Did it run? Did it error?  Nothing.  Hmm.. So I work out I can add a line to tell me the script is running:

Write-Host "Begin"

Cool, so I try again.  Nothing, nada, zip.  No error, no msg.  My script definitely isn't running or I should have seen begin.

One of my colleagues, (Thanks Pete), points out that it could be the execution policy.  I think sure, sounds plausible, but shouldn't there be an error message telling me that the policy won't allow scripts?  You would think so but in this case, NO!

So, I ran:

get-executionpolicy

it returned: Restricted.

"Restricted" is the default policy on any powershell install (Or maybe its OS related, I am on Win 2003).

So I ran:

set-executionpolicy unrestricted

and voila, I could now run my script.

But I'm mad I tell you... MAD!!!!

For more info about this see: http://207.46.16.252/en-us/magazine/2007.09.powershell.aspx

No comments:

Post a Comment