Fix: “Running Scripts is disabled on this System” Error

Powershell is widely used for automating tasks, ranging from simple to complex, on both Windows and Linux operating systems. It is an object-based shell that was launched in 2006. By leveraging PowerShell, you can save a significant amount of time by automating repetitive and mundane daily administrative tasks.

Powershell scripts consist of commands, cmdlets, functions, loops, and logic. Once you’ve written a PowerShell script, you can save it in a file with the extension .ps1. However, if this is the first time you are running PowerShell scripts on your Windows computer, you may encounter an error message: ‘File <script path> cannot be loaded because Running scripts is disabled on this system‘.

To run a PowerShell script on your system, follow the steps below:

  • Login on your Windows 10 or Windows 11 device.
  • Click on Start > Search for Powershell.
  • Open Windows Powershell.
  • Try to Execute Powershell script, For Example, .\Test.ps1.
  • You may encounter the following error message after executing the PowerShell script:
PS C:\test1> .\Test1.ps1
.\Test1.ps1 : File C:\test1\Test1.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.
At line:1 char:1
.\Test1.ps1
~~~ CategoryInfo : SecurityError: (:) [], PSSecurityException
FullyQualifiedErrorId : UnauthorizedAccess
PS C:\test1>
Powershell script cannot be loaded because running scripts is disabled on this system
Powershell script cannot be loaded because running scripts is disabled on this system

Fix “Running scripts is disabled on this system” Error

To fix the ‘Running scripts is disabled on this system’ error, you need to set the PowerShell Execution Policy on your local computer. PowerShell’s execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature is designed to prevent the execution of malicious scripts.

The PowerShell Execution Policy can be set to one of the following five levels:

  • Restricted – The execution of PowerShell scripts is disabled on your system.
  • RemoteSigned – Requires a digital signature from a trusted publisher for scripts downloaded from the internet. Scripts written on the local system do not need to have a digital signature.
  • AllSigned – Only digitally signed scripts are allowed to run.
  • Unrestricted – All PowerShell scripts can be executed without restriction.
  • Bypass – To bypass the PowerShell Execution Policy entirely.

To run PowerShell scripts on your system, you can set the PowerShell execution policy to either RemoteSigned or Unrestricted. Alternatively, you can use ‘Bypass‘ to bypass the execution policy and run the scripts on the system.

  • On Windows client computers the default Powershell Execution policy is Restricted.
  • On Windows Servers the default Powershell Execution Policy is RemoteSigned.
  • On non-Windows computers, the default execution policy is Unrestricted and cannot be changed. 

Set Powershell Execution Policy to RemoteSigned

To resolve the ‘File <script path> cannot be loaded because Running scripts is disabled on this system‘ error, you can set the PowerShell execution policy to RemoteSigned. This is the safest option, as it ensures that only scripts digitally signed by a trusted publisher will be allowed to run on your system.

To set the PowerShell Execution Policy to RemoteSigned, run the following command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

After executing the command, you will receive the prompt/warning message ‘Do you want to change the execution policy?’ Type ‘A‘ and press Enter to accept all warning messages and suppress further prompts. If you prefer not to be prompted, you can use the -Force parameter with the command.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Set Powershell Execution Policy to Unrestricted

To resolve the ‘File <script path> cannot be loaded because Running scripts is disabled on this system‘ error, you can set the PowerShell execution policy to Unrestricted. This setting allows the running of PowerShell scripts on the device without any restrictions.

Even if the PowerShell script is not digitally signed, setting the PowerShell execution policy to Unrestricted will allow that script to execute. After you set the PowerShell execution policy to Unrestricted, you need to ensure that the PowerShell script you are running on your device does not contain any malicious code.

To set the PowerShell Execution Policy to Unrestricted, run the following command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

After executing the command, you will receive the prompt/warning message ‘Do you want to change the execution policy?’ Type ‘A’ and press Enter to accept all warning messages and suppress further prompts. If you prefer not to be prompted, you can use the -Force parameter with the command.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Set Powershell Execution Policy to Bypass

To resolve the ‘File <script path> cannot be loaded because Running scripts is disabled on this system’ error, you can also set the PowerShell execution policy to Bypass. This is typically used for running one-off scripts, as the Bypass switch will entirely bypass the PowerShell execution policy.

To set the PowerShell Execution Policy to Bypass, run the following command:

powershell -executionpolicy Bypass -File .\Test1.ps1
Set Powershell Execution Policy to Bypass
Set Powershell Execution Policy to Bypass

Powershell Execution Policy Location in Registry

Powershell execution policy is stored in HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell under a registry entry Executionpolicy. To check the PowerShell execution policy in the Windows registry, please follow the steps below:

  • Login on a Windows device.
  • Go to Start and search for Registry Editor.
  • Open Registry Editor
  • Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
  • On the right-hand side, you will find a registry entry called ExecutionPolicy, which provides information on the currently set PowerShell execution policy.
Powershell Execution Policy Location in Registry
Powershell Execution Policy Location in Registry
  • You can also retrieve the PowerShell execution policy from the registry using the following command:
get-itemproperty "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" -Name executionpolicy | select ExecutionPolicy
Powershell Execution Policy Location in Registry

Conclusion

In this blog post, we have addressed how to resolve the error ‘File <script path> cannot be loaded because Running scripts are disabled on this system‘ while executing PowerShell scripts. This issue is often caused by the default execution policy set on Windows systems.

Nevertheless, changing the execution policy on your system is a straightforward process with a simple command. If you are writing scripts locally and intend to run them on the same computer, it is recommended to set the PowerShell execution policy to RemoteSigned.

For running scripts on a test device, especially those signed or unsigned scripts downloaded from the internet, setting the execution policy to Unrestricted is an option. However, I highly recommend thoroughly reviewing the script contents before executing any script downloaded from the internet to ensure it does not contain any malicious code.

Leave a Comment

Discover more from TechPress

Subscribe now to keep reading and get access to the full archive.

Continue reading