PowerShell script will not start due to execution policy settings

PROBLEM

When you try to execute a PowerShell script the following error occurs:

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

At line:1 char:23

+ c:\scripts\myscript.ps1 <<<<

CAUSE

By default the PowerShell execution policy is set to restricted, which does not allow the PowerShell Scripts to be run. There are 4 possible execution policies in PowerShell:

  • Restricted – the default setting, doesn’t allow any scripts to run.
  • AllSigned – only runs scripts which are signed by a trusted digital certificate
  • RemoteSigned – runs local scripts without requiring them to be trusted. Scripts downloaded from the Internet  must be trusted before they can run.
  • Unrestricted  – allows all scripts to run, even untrusted ones.

SOLUTION:

Use the Set-ExecutionPolicy command to “unlock” you work environment. For example if you are using a lab or learning environment you can issue the following command :

Set-ExecutionPolicy Unrestricted

IMPORTANT: This setting should not be used in a production environment because it could potentially allow scripts downloaded from internet or planted by viruses to be executed.  For a production use AllSigned or eventually Remote Signed policies

http://www.exchangemaster.net/index.php?option=com_content&task=view&id=65&Itemid=57

Leave a comment