While trying to run a PowerShell script (
.ps1 file), sometimes you can get the cannot be loaded because running scripts is disabled on this system message.
It is not an error but a security feature to prevent you from running any potentially harmful scripts. You can easily fix this issue by changing the execution policy for PowerShell scripts. Entering a single command should be enough.
Cannot Be Loaded Because Running Scripts Is Disabled
The only reason this issue occurs is because of the PowerShell execution policy. It usually happens due to following reasons:
- You are running an unsigned PowerShell script.
- Execution policy is set to restrict all PowerShell scripts.
How to Fix Cannot Be Loaded Error
Here’s how you can make it possible to run the PowerShell script:
- Open the admin level terminal for Windows PowerShell or the IDE you are currently using.
Get-ExecutionPolicy. It shows the policy for the current PowerShell session. You can also enter
Get-ExecutionPolicy -Listto list out the policies for all scopes.
- Change the execution policy for the scope you want.
- The command you need for this purpose is:
Set-ExecutionPolicy -ExecutionPolicy <policy name> -Scope <scope>. See below to know the possible values for the policy name and scope.
- In general, we recommend using
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned, as it is more secure.
- If it doesn’t solve the issue, enter:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
If you have both 64-bit and 32-bit PowerShell, you must enter this command for both terminals. Their locations are:
Possible values for
- Restricted: Disallows running scripts.
- All Signed: Permits running signed scripts only
- RemoteSigned: Allows running all scripts from the local computer but only signed ones for scripts you download.
- Unrestricted: Permits running all scripts but warns before running external scripts
- Default/Undefined: Restricted for clients and RemoteSigned for servers.
- Bypass: Permits all scripts, and you get no warning.
- MachinePolicy: Group-level policy for all users
- UserPolicy: Group-level policy for the current user
- Process: Temporary policy for current PowerShell session
- CurrentUser: Registry policy configuration for the current user
- LocalMachine: Registry policy configuration for all users