February 21, 2013

Execution Policy for PowerShell

When trying to execute a PowerShell script you may encounter this error message:

File [Path]\[filename].ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess


To check your execution policy, run Get-ExecutionPolicy  (be sure to check 32 & 64 bit).
To change your execution policy, run Set-ExecutionPolicy [Policy level] ... I suggest starting with 'AllSigned', one step below 'Restricted'.  If you get the below message you need to launch PowerShell as Administrator:

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.

 
Once complete, you'll see a registry entry at that location String named 'ExectionPolicy', Data '[Policy level]'

Options for Policy level are:
  • Restricted
  • AllSigned
  • RemoteSigned
  • Unrestricted