Cannot be loaded because running scripts is disabled on this system Windows 11

You have created your first Powershell script ( congratulations! ), trying to run it on the command line. Suddenly you see the error telling you, you cannot run it, as it is disabled on this system?

Here is the error message: your script name cannot be loaded because running scripts is disabled on this system.

Full error message:

PS C:\Users\codetryout\Documents> .\my-script.ps1 .\my-script.ps1 : File C:\Users\codetryout\Documents\my-script.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 + .\my-script.ps1 + ~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess PS C:\Users\codetryout\Documents>

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

If you see this error when you try to run a PowerShell script, you can follow the below steps.

  • Go to Windows Start Menu
  • Type Powershell
  • From the listing Right click on the Powershell
  • Run as Administrator
  • Once the Powershell window is opened, set the below execution policy as shown below
Set-ExecutionPolicy RemoteSigned
  • Select A when prompted. ([A] Yes to All)

Demo to set PowerShell RemoteSigned Execution Policy :

PS C:\> Set-ExecutionPolicy RemoteSigned Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A PS C:\>

Make sure to revert the policy, after you are done

To change the execution policy back to restricted mode, Open the PowerShell as admin again as described above and run,

Set-ExecutionPolicy Restricted

Demo to set PowerShell Restricted Execution Policy:

PS C:\> Set-ExecutionPolicy Restricted Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A PS C:\>

Note: This is for your information purpose only, if you make any changes as administrator, ensure that you have the ownership of the system to do so.

FAQ:

How to check the current user execution policy?

To check the current user execution policy, the command is:

Get-ExecutionPolicy -Scope CurrentUser

To check the effective execution policy:

Get-ExecutionPolicy

How to Set-ExecutionPolicy Restricted?

To configure PowerShell execution policy to restricted mode

Set-ExecutionPolicy Restricted

How to set executionpolicy unrestricted?

You may be interested to read more about PowerShell execution policy restrictions, please refer to : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies

Fix - ng.ps1 cannot be loaded because running scripts is disabled on this system #

The error "ng.ps1 cannot be loaded because running scripts is disabled on this system" occurs when the execution policy does not allow running the specific script on Windows. Use the Set-ExecutionPolicy -ExecutionPolicy RemoteSigned command to solve the error.

Open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command.

Copied!

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

The Set-ExecutionPolicy command sets the PowerShell execution policy for the Windows computer.

The RemoteSigned execution policy is the default execution policy for Windows server computers. It requires that all scripts and configuration files that were downloaded from the internet are signed by a trusted publisher.

This effectively removes the execution policy of Restricted, which doesn't allow us to load configuration files or run scripts. The Restricted execution policy is the default for Windows client computers.

Make sure to open your PowerShell as an administrator before you run the Set-ExecutionPolicy command.

If you aren't able to run the command as an administrator, try running it with the CurrentUser parameter.

Copied!

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

The RemoteSigned policy still prevents us from running unsigned scripts.

Now, run the Get-ExecutionPolicy command:

Copied!

Get-ExecutionPolicy

The Get-ExecutionPolicy command should display the effective execution policy for the current PowerShell session (RemoteSigned).

If you get RemoteSigned back, then you have successfully updated your permissions and are able to run the ng command.

You can also run the command with the -List parameter to display the execution policies for each scope in the order of precedence.

Copied!

Get-ExecutionPolicy -List

When ran with the -List parameter, the command returns a list of all execution policy values for the session listed in precedence order.

The command should show that the RemoteSigned policy is set for the default scope (LocalMachine).

Alternatively, you can try to delete the C:\Users\Your_User_Name\AppData\Roaming\npm\ng.ps1 file and restart your terminal.

Make sure to replace the Your_User_Name placeholder with your actual username.

After restarting your terminal, try running the command again.

If that doesn't help, clear your npm cache and re-run the command.

Copied!

# 👇️ clean npm cache npm cache clean --force

If nothing else works, you can try to set the execution policy to Unrestricted, which means that the system would allow unsigned PowerShell scripts to run.

Copied!

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Starting with PowerShell 6.0, Unrestricted is the default execution policy for non-Windows computers and can't be changed.

The policy loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the internet, you would still get prompted for permission before it runs.

How do I enable scripts in Windows 11?

How to Enable Running Scripts in Windows 11/10.
Step 1 : Go to your start menu and type “cmd”. ... .
Step 2 : Type in the first command promt “Get-ExecutionPolicy -List” and hit Enter..
Step 3 : Type in the second command “Set-ExecutionPolicy Unrestricted” and hit Enter again..
Step 4 : ... .
Step 5 :.

Why is running scripts disabled on this system?

While running PowerShell script, if you get running scripts is disabled on this system, it is because the PowerShell execution policy is set up by default as Restricted and doesn't allow to run script. PowerShell has built-in security features implemented.

How do I turn off scripts in Windows 11?

To do this, input “Get-ExecutionPolicy” (without quotes) and press Enter on your keyboard. PowerShell will return a value of Restricted. c) To change the script execution policy, use the Set-ExecutionPolicy cmdlet. Input “Set-ExecutionPolicy unrestricted” (without quotes) and press Enter on your keyboard.

How do I enable running scripts on my system?

* Note: If you still receive the error "Scripts are disabled on this system", give one of the following commands and try again to run your script: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned. set-executionpolicy remotesigned.