When you try to execute a PowerShell script on the PowerShell console, you get an error message File <script path> cannot be loaded because running scripts is disabled on this system. Below is a snippet of the error message:
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 FullyQualifiedErrorId : UnauthorizedAccess PS C:\test1> |
Below is a screenshot of the error message:
You may also get the following error message:
The file <file path> 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 at https://go.microsoft.com/fwlink/?LinkID=135170.
Contents
Understanding the Cause of This Error Message
By default, PowerShell is installed on Windows computers with execution policy set to Restricted, which means that execution of PowerShell scripts is disabled. This could be causing the error message: running scripts is disabled on this system.
If you change PowerShell execution policy to RemoteSigned and execute a script downloaded from internet and does not have a digital signature from a trusted publisher. You may get an error: The file <file path> is not digitally signed.
Fixing the Error Message
You can easily fix this error message by setting the execution policy on the PowerShell console, which allows script execution. You can set PowerShell execution policy to one of the following:
- 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 does not require 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.
- On Windows client computers, 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.
Check Current Execution Policy
Check the PowerShell execution policy currently set on your computer by using Get-ExecutionPolicy
cmdlet. Open PowerShell console in admin mode and execute this command.
Check PowerShell execution policy
Get-ExecutionPolicy
Set PowerShell Execution Policy
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 that are digitally signed by a trusted publisher are allowed to run.
Set PowerShell execution policy to RemoteSigned
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 PowerShell execution policy to RemoteSigned without getting any prompt
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
Set PowerShell Execution Policy to Unrestricted
To resolve File <script path> cannot be loaded because running scripts is disabled on this system error, you can also set the PowerShell execution policy to Unrestricted.
This option allows the PowerShell scripts to execute even if they are not digitally signed. Use the following command to set the execution policy to Unrestricted.
Set PowerShell execution policy to Unrestricted
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 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.
Set PowerShell execution policy to Bypass
powershell -executionpolicy Bypass -File .\Test1.ps1
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:
- Open the Registry Editor on a Windows device.
- 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.
- You can also retrieve the PowerShell execution policy from the registry using the following command.
Retrieve PowerShell execution Policy using a PowerShell command
get-itemproperty "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" -Name executionpolicy | select ExecutionPolicy
Set Execution Policy as Non-Administrator
When you are not an administrator on the device, you will not be able to open PowerShell console in Admin mode and therefore will not be able to set the execution policy.
When you open PowerShell console as an administrator and set PowerShell execution policy, it makes the change on computer level which will apply to all users who use the device. However, when you want to change the execution policy and apply it only in the current user scope, you will not require any administrator rights.
- Open PowerShell console and use a switch
-Scope CurrentUser
with Set-ExecutionPolicy cmdlet. As an example, the below command will set the execution policy to RemoteSigned for only the user who is currently signed in to the device.
Set PowerShell execution policy for Current User scope
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser