Amending Powershell Execution Policies

Powershell Policies

Running Powershell scripts on your computer can at times be limited due to something called Powershell Execution Policies. It’s a feature of Windows to prevent execution of malicious scripts and it will manifest itself with the following error:

File C:\my_powershell_file.ps1 cannot be loaded. The file C:\my_powershell_file.ps1 is not digitally signed. You cannot     
run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Listing Execution Policies

To get better understanding of the Execution Policies run the following command.

Get-ExecutionPolicy -List

It’ll list all the policy scopes and types on your workstation.

Read more about policy types and policy scopes.

MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       AllSigned

Amending Execution Policies

You can set the policy type per scope with the following command. The one below will allow to execute downloaded and signed scripts executed in the context of current user, i.e. me.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Listing Execution Policies again will now show you the following outcome.

MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine       AllSigned

And this is it – now you know how to allow these ps1 scripts execute again on your Windows machine.

Marcin Narloch

Marcin Narloch

Creative and out-of-the-box thinker with strong interests and knowledge in technology and innovation.
NET Core SDKs Previous post Fix Missing NET Core SDKs
Kubernetes cloud Next post Kubernetes in the Cloud: AKS vs GKE vs EKS

Leave a Reply

Your email address will not be published.