If you encounter an error Running Scripts is Disabled on this system while executing the scripts in PowerShell, then this article will help you to fix this issue. Once you received this error you can see the following full error message.
File C:\Common\Scripts\Basescript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details. At line:1 char:13 + .\Basescript.ps1 <<<< + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException
Windows PowerShell is a command-line shell and scripting language designed especially for system administration. Its analogue in Linux is called as Bash Scripting. Built on the .NET Framework, Windows PowerShell helps IT professionals to control and automate the administration of the Windows operating system and applications that run on the Windows Server environment. Using PowerShell, you can easily create the script on Windows. PowerShell offers you the best scripting environment and tools to create scripts easily. If you are executing the Scripts for the first time in Windows, then you’ll receive the Running Scripts is Disabled on This System error. Follow the below-mentioned methods to fix this error.
Fix Running Scripts is Disabled on This System in PowerShell:
Using the following methods, you can easily avoid the running scripts disabled error on Windows 11/10.
Solution 1: Bypass the Execution Policy:
Click on the Start menu and search for Windows PowerShell, Right-click on it and choose Run as Administrator. So you need to open the PowerShell in elevated mode.
Next Run the following command to bypass the execution Policy.
powershell -ExecutionPolicy ByPass -File ScriptFileName.ps1
So, if you are going to run any script file, before that you need to use this command, replace the name of the Script file here, and copy-paste the command in the PowerShell window, and hit enter.
This will bypass the Execution Policy and it will allow you to run the script. But this won’t work for the automated script. If you want the permanent fix then follow the next solution.
Solution 2: Set the Execution Policy to Unrestricted:
Type windows Power shell on windows search, Right-click on windows Power shell, and select Run as admin. This will open the windows power shell in admin mode.
Now type the following command to Unrestrict the Execution Policy.
get-executionpolicy
This command will show the execution Policy is restricted or Not. As per the image, the policy is now restricted to enable this policy type below mentioned command.
Next, type the following command to unrestrict all the policy,
Set-ExecutionPolicy unrestricted
Type [Y]–> yes
Type [A]–>yes To All
Type [N]–> NO
Type [L]–>No to All
Type [S]–>Suspend
Type A and hit enter, this will restrict all the Policy. Now you can run any script you want.
There are four different modes in Script execution policy, you can use the following commands to set the Execution Policy.
Restricted – By default this mode will be there in PowerShell and it doesn’t allow you to run any script.
AllSigned – This mode will allow you to run only the signed and authorized scripts.
RemoteSigned – This mode will allow you to run only trusted signature scripts.
Unrestricted – You can run any scripts you want, This mode will allow you to run all the scripts.
Solution 3: Enable Windows PowerShell Script Execution:
Follow this article to Enable Windows PowerShell Script Execution using GPO and Registry Editor.