If you get ‘PowerShell running scripts is disabled on this system’ error message when you try to run a PS script even as the Administrator, you are at the right place to find out how to solve it.
For security reasons, the script execution is blocked by default. The PowerShell execution policy controls it.
How to Solve?
By default, the PowerShell execution policy is set to restricted. We can unstrict the policy to run the scripts without the above error.
Execute the following command in PowerShell (Open it as Administrator)
Now, run the same script which was not working earlier. That should work.
There are a few options/keys you must know while editing this policy.
- Restricted – No scripts can be run.
- AllSigned – Only scripts signed by a trusted publisher can be run.
- RemoteSigned – Downloaded scripts must be signed by a trusted publisher. This is the ideal option in most cases.
- Unrestricted – No restrictions; all Windows PowerShell scripts can be run. If none of the above options works, then you can try ‘Unrestricted.’
For more information, check the Microsoft guide here.
To find out what type of PowerShell execution policy is in place on your Windows 11/10 computer, run the below command.
Microsoft recommends disabling the PowerShell script running policy after completing purposeful manual script execution. It is one of the best security practices on Windows client or Server operating systems.
So, it is better to restrict it again.
To do it, run the below command.
Set-ExecutionPolicy -ExecutionPolicy Restricted
Now check the status.
It will show as restricted. So, when you run the earlier script, you will get the same error now.
If you want to run a single PowerShell script, then you can bypass the existing restriction.
Here is the command to do that.
powershell -ExecutionPolicy Bypass -File script.ps1
As you can see, it ran successfully without modifying the existing policy.
In this article, we showed how to enable the Powershell execution policy to run the scripts and avoid the “cannot be loaded because running scripts is disabled on this system” error. Also, it is recommended to set back the policy to default settings once we complete running the required PowerShell scripts.