You run a script, or just type npm, and PowerShell stops you with this:
File C:\scripts\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.
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

Nothing is broken. Windows PowerShell ships with an execution policy of Restricted on client editions of Windows, and Restricted means no script file runs at all, not even one you wrote yourself. One command changes that for your own account, and it does not need an admin console.
The Fix
# your account only, no admin needed: local scripts run, downloaded ones must be signed Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Answer Y to the prompt and run the script again. The change takes effect immediately, needs no restart, and stays set for your user. RemoteSigned is the policy Microsoft already uses by default on Windows Server and in PowerShell 7, so you are not loosening anything unusual.
If you want the same for every account on the machine, open PowerShell as Administrator and set the LocalMachine scope instead. That is the version in the screenshot:
# every user on this machine, needs an elevated console Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned

Either way, confirm it took:
Get-ExecutionPolicy -List

One Session or One Run Only
On a shared or locked-down machine you may not want to change a setting at all. The Process scope lives in the current window and is gone when it closes, and the launch parameter does the same for a single run. Neither needs admin rights.
# this window only Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass # one run, nothing saved anywhere powershell.exe -ExecutionPolicy Bypass -File .\script.ps1 pwsh -ExecutionPolicy Bypass -File .\script.ps1
That second form is also the one that belongs in a scheduled task or a build step, which is covered in Run PowerShell Scripts with Task Scheduler.
The Same Error From npm, npx, Activate.ps1 and Other Tools
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.
Node (npm.ps1, npx.ps1), Python virtual environments (Activate.ps1) and a growing list of command line tools ship a small PowerShell wrapper next to their .cmd one. When both sit on the PATH, PowerShell picks the .ps1 first, so the wrapper hits the policy before the tool even starts. Tested on PowerShell 7.7 with a folder holding both hello.ps1 and hello.cmd: typing hello runs the .ps1.
The fix is the same CurrentUser command above. If you cannot change the policy, go round the wrapper instead:
# call the .cmd wrapper by name, which the policy does not touch npm.cmd install npx.cmd create-next-app my-app # a venv works without Activate.ps1: run its own interpreter directly .\.venv\Scripts\python.exe -m pip install requests .\.venv\Scripts\python.exe app.py
Which Scope Is Doing the Blocking
# every scope, in precedence order Get-ExecutionPolicy -List

The list is ordered by precedence and the first defined value from the top wins. MachinePolicy and UserPolicy come from Group Policy and beat everything, then Process, then CurrentUser, then LocalMachine. Run it in the exact console that is refusing the script. It takes five seconds and tells you which scope is blocking instead of leaving you to guess.
Changing LocalMachine needs an elevated console. If the option is not where you expect, there is a short guide to opening PowerShell as Administrator on sqldba.blog. CurrentUser and Process need no admin rights at all.
Fixed, Then Blocked Again: “is not digitally signed”
RemoteSigned fixes the original error, and then a script you downloaded in a browser or copied from a network share fails with a new message. Different problem, different fix:
.\script.ps1 : File C:\scripts\script.ps1 cannot be loaded. The file C:\scripts\script.ps1 is not digitally signed. You cannot run this script on the current system.
Windows stamps downloaded files with the mark of the web, a small Zone.Identifier stream on the file. Under RemoteSigned, local scripts run but anything carrying that stamp counts as remote and must be signed. The fix is Unblock-File, not a looser policy:
# remove the mark of the web from one script Unblock-File .\script.ps1 # or from everything in a folder you just pulled down Get-ChildItem .\scripts\*.ps1 | Unblock-File
Verified end to end on PowerShell 7.6: a script stamped with ZoneId=3 is blocked under RemoteSigned with the message above, and runs immediately after Unblock-File. Files fetched with curl.exe or Invoke-WebRequest are not stamped, so this mostly bites on browser downloads, email attachments and files copied from a share.
Windows PowerShell 5.1 and PowerShell 7 Keep Separate Policies
If you fix the policy in the blue Windows PowerShell console and the script still fails in pwsh, or the other way round, nothing is broken. The two store their execution policies separately, so a change in one does not carry across. Their defaults differ too: Windows PowerShell is Restricted on client Windows, while PowerShell 7 reports RemoteSigned out of the box (7.6 and 7.7 both do here). Run Get-ExecutionPolicy -List in the console you are actually using, then fix that one.
When Set-ExecutionPolicy Does Not Stick
On a domain-managed machine, Set-ExecutionPolicy can report that it updated the policy but that the setting is overridden by a policy defined at a more specific scope. That is Group Policy. If MachinePolicy or UserPolicy shows a value in Get-ExecutionPolicy -List, no local change at any scope will win, Process included.
The honest answer there is a conversation with whoever owns the GPO, not a workaround. The policy exists because someone decided unsigned scripts should not run on that estate, and as a DBA I would rather ask for a signed-scripts process than quietly defeat the control. Say what you need to run and where, and the exception is usually straightforward.
What Each Policy Means
- Restricted: commands run, script files do not. The Windows PowerShell default on client Windows.
- RemoteSigned: local scripts run, downloaded scripts must be signed or unblocked. The default on Windows Server and in PowerShell 7, and the right setting for most people.
- AllSigned: every script must be signed by a trusted publisher, including your own.
- Unrestricted: everything runs, with a warning before scripts that did not come from the local intranet zone.
- Bypass: everything runs, no warnings, no prompts. Fine for a Process scope or a scheduled task, not for a permanent setting.
- Undefined: nothing set in that scope. If every scope is Undefined, the effective policy is Restricted on Windows clients and RemoteSigned on Windows Server.
Microsoft’s own reference is about_Execution_Policies, the page the error message points at. One line from it worth keeping in mind: the execution policy is not a security boundary, it is there to stop you running a script by accident.
Frequently Asked Questions
Is RemoteSigned safe?
It is the default Microsoft chose for Windows Server and for PowerShell 7. Your own scripts run, anything downloaded must be signed or deliberately unblocked. Unrestricted and a permanent Bypass are the ones to avoid.
Do I need to run PowerShell as Administrator?
Not for the CurrentUser or Process scopes, which is why the fix above uses CurrentUser. Only the LocalMachine scope needs an elevated console.
I ran the command and the script still will not run. Why?
Run Get-ExecutionPolicy -List in the same console. If MachinePolicy or UserPolicy has a value, Group Policy is overriding you. If the message now says “is not digitally signed”, the file carries the mark of the web and needs Unblock-File. And check you fixed the right PowerShell, 5.1 and 7 are separate.
Does this apply to the terminal in VS Code?
Yes. The integrated terminal is an ordinary PowerShell session, so it uses the same policy and the same fix. The only thing to check is which PowerShell VS Code launched, $PSVersionTable.PSVersion tells you.
How do I put the policy back?
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined removes your setting and the machine default applies again.
What about PowerShell on Linux or macOS?
There is no execution policy to set. Get-ExecutionPolicy reports Unrestricted and it cannot be changed, because those platforms have no Windows security zones to enforce.
Related
- How to Automate PowerShell Scripts with Task Scheduler
- How to Check PowerShell Version on Windows
- Get-Command in PowerShell
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.
Leave a Reply