Fix for PowerShell Script cannot be loaded because running scripts is disabled on this system error
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, I 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.”
In some cases, it’s a “The file 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.” error.
Root Cause:
This is due to the Windows PowerShell execution policy being set to prevent untrusted scripts which 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 scripts from running.
Solution for “cannot be loaded because running scripts is disabled on this system“:
How do you enable running scripts is disabled on this system error? To fix this issue, we have to set the execution policy using the Set-ExecutionPolicy cmdlet, so that the PowerShell script runs on the particular machine. Here is how to permit PowerShell script execution:
- Open PowerShell Console by selecting “Run as Administrator” (Or Right-click the Start menu and choose “Windows PowerShell (Admin)” from the context menu) and get the execution Policy with the command: Get-ExecutionPolicy to get the current policy applied, such as “Restricted”.
- Set the execution Policy with the following command: Set-ExecutionPolicy RemoteSigned
- Type “Y” when prompted to proceed.
You can also use Set-ExecutionPolicy Unrestricted to remove all restrictions on your security policy (However, the RemoteSigned execution policy is ideal!). Once you have changed the execution policy, you should be able to run scripts without encountering the “running scripts is disabled on this system” error.
The RemoteSigned policy requires scripts and configuration files from the internet must be signed by a trusted publisher. Behind the scenes, it sets the registry key: HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell . The policy parameter takes the below values:
- Restricted – No scripting allowed
- Unrestricted – You can run any script, No signing is required.
- RemoteSigned – Good for Test, Dev environments. Only files from the internet need to be signed. This is the default setting on servers.
- AllSigned – local or remote script – It should be signed by a trusted publisher.
What if you can’t set the Execution Policy by running PowerShell as Administrator?
To set the execution policy for the current user scope, use the following:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
The default scope is “LocalMachine”, which sets the policy for all users of the current machine.
Bypass ExecutionPolicy Temporarily for a Session
You can bypass the execution policy just for a one-time session. In the command prompt, type: PowerShell -ExecutionPolicy Bypass
Once you close the PowerShell window, the current PowerShell session ends, and the Bypass is also closed with it. This allows you to run a PowerShell script temporarily while keeping the ExecutionPolicy settings for all other PowerShell sessions.
How about running the script in PowerShell ISE?
You can bypass the execution policy by selecting a block of the script and then hitting F8 (Run Selection).
Use Group Policy Object to Set Execution Policy for Multiple Computers
If you want to change the execution policy on multiple computers, you can use Group Policy in your Domain controller. Here is how:
- Open the Group Policy Editor.
- Under “Local Computer Policy”, Navigate to Computer Configuration >> Administrative Templates >> Windows Components >> Windows PowerShell
- Enable the “Turn on Script Execution” policy, Then select the desired execution policy from the drop-down list, such as “Allow local scripts and remote signed scripts”, which is equivalent to the “RemoteSigned” property we set using Set-ExecutionPolicy command.
Here is the Microsoft reference: Configure execution policies
Wrapping up
The “running scripts is disabled on this system” error in PowerShell can be frustrating, but it is easily fixed by changing the execution policy. By understanding execution policies and following the steps outlined in this article, you can enable script execution and take advantage of PowerShell’s powerful automation capabilities.
Thank you!
thank you ( rahmat )
thank you
Thank you!
I found it very helpfull.The step-by-step instructions provided are easy to follow and allowed me to quickly resolve the issue. Overall, it’s a great resource for anyone who needs to enable script running in PowerShell and is experiencing this error.
Thanks, works fine.
I am getting an issue though where if I right-click the script and click ‘Run with PowerShell’, the script seems to execute regardless of execution policy.
Is this expected behaviour?
Yes! The “Run with PowerShell” actually bypasses the execution policy.
Thanks It Works.
Thank you very much!
worked for me! thank you!
God bless! Worked like a charm.
Neede for VScode to run nodemon, this fixed it, thanks
Thank you bro
Nice article, I don’t work with PS much, so this was very helpful.
Thanks, its working
This was easy answer. Thank you.
Thanks for this article, though the registry is set to RemoteSigned I am still getting the error displayed, I cant figure out what I am doing wrong, any help would be greatly appreciated
I appreciate your blog; it is helpful.
thanks a lot, this helped me!
Thank you
Thank you!
Amazing. Thanks!
Thank you
Thanks!
thanks
Thank you very much Sir, I appreciate this.
Thank you really worked the solution
Thank you 🙂 It’s working
thanks a lot. It worked.
thanks
thanks.
Worked like a charm!!
Thank you. It’s working.
Thanks a lot. It helped me.
Thanks a lot!
Thanks. You saved my day !
That Actually Helped, Thanks a bunch, easy and smooth answer