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.