Fix for PowerShell Script cannot be loaded because running scripts is disabled on this system error

Problem: Getting “cannot be loaded because running scripts is disabled on this system” error!

On trying to run a PowerShell script from the PowerShell console, received this error message: “File C:\temp\GenerateRpt.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.”

cannot be loaded because running scripts is disabled on this system

Root Cause:

This is due to the Windows PowerShell execution policy being set to prevent untrusted scripts which can affect your Windows client environment. The default execution policy is “strict” on client operating systems like Windows 10 PC.

Solution for “cannot be loaded because running scripts is disabled on this system:

How do you enable running scripts is disabled on this system error? To fix this issue, we have to set the execution policy, so that the PowerShell script runs on the particular machine. Here is how:

  1. Open PowerShell Console by selecting “Run as Administrator” and get the execution Policy with the command: Get-ExecutionPolicy to get the current policy applied, such as “Restricted”. PowerShell Run as Administrator
  2. Set the execution Policy with the following command: Set-ExecutionPolicy RemoteSigned
  3. Type “Y” when prompted to proceed.

You can also use Set-ExecutionPolicy Unrestricted to remove all restrictions on your security policy (However, the RemoteSigned execution policy is ideal!).

The RemoteSigned policy requires scripts and configuration files from the internet must be signed by a trusted publisher. Behind the scenes, it sets the registry key: HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell . The policy parameter takes the below values:

  • Restricted – No scripting allowed
  • Unrestricted – You can run any script, No signing is required.
  • RemoteSigned – Good for Test, Dev environments. Only files from the internet need to be signed. This is the default setting in servers.
  • AllSigned  – local, remote script, it should be signed by a trusted publisher.
Fix for PowerShell Script cannot be loaded because running scripts is disabled on this system error

What if you can’t set the Execution Policy by running PowerShell as Administrator?

To set the execution policy for the current user scope, use:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

The default scope is “LocalMachine” which sets the policy for all users.

Bypass ExecutionPolicy Temporarily for a Session

You can bypass the execution policy just for a one-time session. In the command prompt, type: PowerShell -ExecutionPolicy Bypass

Once you close the PowerShell window, the current PowerShell session ends and the Bypass is also closed with it. This allows you to run a PowerShell script temporarily while keeping the ExecutionPolicy settings for all other PowerShell sessions.

How about running the script in PowerShell ISE?

You can bypass the execution policy by selecting a block of the script and then hitting F8 (Run Selection).

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

9 thoughts on “Fix for PowerShell Script cannot be loaded because running scripts is disabled on this system error

Leave a Reply

Your email address will not be published.