PowerShell Execution Policy Settings

Shell

CC 2.0 image courtesy GarrettTT on Flickr

If you have ever tried to run a PowerShell script on a new system, you probably have encountered the following error: “{File Name} cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details“.

PS01

This post looks at the solution to resolve this issue.

Cause

The reason the error message is displayed is due to the security settings within PowerShell. The ExecutionPolicy determines if scripts may run on your computer. The default setting (in Windows 8, Windows Server 2012, and Windows 10) is Restricted.

To view the current execution policy on your machine, use the Get-ExecutionPolicy PowerShell command:

Get-ExecutionPolicy

PS02

Resolution

There are four different execution policies in PowerShell:

  • Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted – No restrictions; all Windows PowerShell scripts can be run.

To change the execution policy on your machine, use the Set-ExecutionPolicy PowerShell command:

Set-ExecutionPolicy

To see more details about Set-ExecutionPolicy, use the Help feature:

Get-Help Set-ExecutionPolicy

PS03

To use the Set-ExecutionPolicy command, it must be executed in a PowerShell window with elevated administrator permissions. To do so, right-click Windows PowerShell and select Run as Administrator. Once you are in an elevated prompt, run the following command:

Set-ExecutionPolicy Unrestricted

The execution policy on your machine has been changed.

PS04

Note: If you want to revert PowerShell to its original Restricted execution policy to prevent future scripts from running, use the following command via an elevated command prompt:

Set-ExecutionPolicy Restricted

Conclusion

This article has shown you how to change the execution policy on your computer so you can successfully run PowerShell scripts.

Advertisements

About Ken Cenerelli
I am a Programmer Writer, .NET Developer, Microsoft MVP - Visual Studio and Development Technologies, Public Speaker, Blogger, and Microsoft Azure Nerd. I blog regularly at kencenerelli.wordpress.com and can be found on Twitter via @KenCenerelli.

One Response to PowerShell Execution Policy Settings

  1. Pingback: Unblock downloaded PowerShell scripts | Ken Cenerelli

Leave a Reply

Please log in using one of these methods to post your comment:

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

%d bloggers like this: