PowerShell Script Cannot be Loaded
Informational
On trying to run a PowerShell script from the PowerShell console, I received this error message: “File C:tempscript.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.”
Root Cause:
This is due to the Windows PowerShell execution policy being set to prevent untrusted scripts that can affect your Windows client environment. Execution policies are security settings that determine the trust level for scripts run in PowerShell. The default execution policy is “strict” on client operating systems like Windows 10, preventing Windows PowerShell commands and scripts from running.
Set the Execution Policy:
Set the execution Policy with the following command:
PS C:/WINDOWS/system32> Set-ExecutionPolicy RemoteSigned
Type “Y” when prompted to proceed. That’s all! This should solve the issue.
You can also use Set-ExecutionPolicy Unrestricted to remove all restrictions on your security policy.
--Restricted – No scripting allowed
--Unrestricted – You can run any script, No signing is required.
--RemoteSigned – Good for Test and dev environments. Only files from the internet need to be signed. Otherwise, you’ll see .ps1 is not digitally signed error. This is the default setting on servers.
--AllSigned – local or remote script – A trusted publisher should sign it; only digitally signed PowerShell scripts are allowed.