Fix the *.ps1 cannot be loaded because running scripts is disabled on this system
When you first try to run a PowerShell *.ps1
script on Windows, you will probably get the following error message:
File C:\Users\Mike\AppData\Roaming\npm\nest.ps1 cannot be loaded because running scripts is disabled on this system.
Why this error occurs
By default, all Windows versions - Windows 11, Windows 10, Windows 7, Windows Server,... - have the script execution disabled for security reasons.
The complete error message looks like this:
PS D:\Projects\test> nest new nest-demo-1
nest : File C:\Users\Mike\AppData\Roaming\npm\nest.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
+ nest new nest-demo-1
+ ~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Enabling script execution
To fix this error, you need to enable script execution by changing the execution policy. You need to take the following steps:
- Open
PowerShell
or theTerminal
as anadministrator
.
If you use the Terminal app then check if it opens a PowerShell Windows: - Execute the following code to allow the script execution:
Set-ExecutionPolicy RemoteSigned
This command will set the execution policy to RemoteSigned, which allows the execution of local scripts that are signed by a trusted publisher. - Execute your original command. It should work without the error.