Problem: Getting “cannot be loaded because running scripts is disabled on this system” error!
On trying to run a PowerShell script from the PowerShell console, received this error message: “File C:\temp\GenerateRpt.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 PowerShell’s policy to prevent untrusted scripts which can affect your Server environment.
Solution for “cannot be loaded because running scripts is disabled on this system“:
To fix this issue, we have to set the execution policy, so that the PowerShell script runs on the particular machine. Here is how:
- Open PowerShell Console by selecting “Run as Administrator” and set the execution Policy with the command: Set-ExecutionPolicy RemoteSigned
- Type “Y” when prompted to proceed
This in fact sets the registry key: HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
Policy parameter takes below values:
- Restricted – No scripting allowed
- Unrestricted – You can any scripting
- No signing required
- Remote signed – good for Test, Dev environments
- Only files from internet need to be signed
- This is the default setting
- All signed – local, remote script, it should be signed.
- user must agree to run script