Search
Free Signup | Login
Search Blogs
Relevant Links
Enabling Execution of PowerShell PS1 Scripts
Location: BlogsRevindexPowerShell    
Posted by: revindex 7/15/2007 4:30 PM

Microsoft finally put together a powerful command line tool for Windows that makes Bash on Linux looks like small potato. The new powershell runs .NET and understands objects when you pipe from one process to another. Given the power and the things you can do with powershell, Microsoft is rightfully cautious about hackers and script abuse. PowerShell, by default, is very secure and disallows any powershell scripts from running. If you try calling a ps1 file, you'll get this error message:

File C:\Temp\Backup.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

To run PowerShell scripts (files that end with .ps1), you must first set the execution policy to Unrestricted.

Set-ExecutionPolicy Unrestricted

Once you do that, Windows will allow you to execute any ps1 file. Enjoy!

Permalink |  Trackback

Comments (4)   Add Comment
Re: Enabling Execution of PowerShell PS1 Scripts    By Nilang on 7/21/2008 3:14 PM
Thanks a lot for your valuable post... it saved my lots of time...

Re: Enabling Execution of PowerShell PS1 Scripts    By Matthew Bearup on 7/30/2008 3:19 AM
Actually, a safer practice is to use the "remotesigned" option, as this will allow you to run all your locally generated scripts, but still offer protection against malicious internet scripts.

And if you're wondering HOW windows knows you got that script from the internet, check out Minasi's post about Alternate Data Streams :)

Cheers,
Matthew Bearup
http://www.bearupweb.net

Re: Enabling Execution of PowerShell PS1 Scripts    By Cyril Gupta on 9/24/2010 10:49 AM
Matthew, I just checked your tutorial about alternate data streams! Awesome! I love it.

Thanks

Re: Enabling Execution of PowerShell PS1 Scripts    By Scott Shuster on 9/24/2010 10:49 AM
An addendum... There appears to be a separate ExecutionPolicy INSIDE the Powershell GUI vs. OUTSIDE the Powershell GUI.

So, if you're getting the ".. scripts are disabled..." message and then go into the Powershell GUI and run the Get-ExecutionPolicy to find that scripts are Unrestricted, don't be frustrated and confused (like I was).

Run the following statement from a Command prompt (not a PS prompt):
c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -command set-executionpolicy unrestricted

Note: you may have to tweak the filepath if you're on a 32-bit system.


Your name:
Title:
Comment:
Add Comment   Cancel