I recently ran into and corrected an issue with my PowerShell execution policy.

In my case, I was trying to install an npm package that was remotely signed, but my execution policy required that all packages be locally signed by a trusted publisher. I received the following error:

File C:\Program Files\nodejs\npm.ps1 cannot be loaded. The file C:\Program Files\nodejs\npm.ps1 is not digitally signed. You cannot run this script on the current system.

Microsoft remotely signed this file, but my PowerShell environment policy prevented me from running it locally.

You can view your execution policy with the following command:

Get-ExecutionPolicy

The possible return values are:

  • AllSigned: All scripts, including locally running scripts must be signed by a trusted publisher
  • Bypass: Signing is not checked. Any script can run.
  • RemoteSigned: Allows running scripts that are signed remotely
  • Restricted: Prevents some but not all scripts from running
  • Undefined: No execution policy set. The operating system policy takes effect.
  • Unrestricted: Unsigned scripts can run. Similar to Bypass, but it warns the user before executing an unsigned script.

My PowerShell session policy was set to "AllSigned."

The solution was to change the executing policy to "RemoteSigned," which I did with the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Running Get-ExecutionPolicy again returned "RemoteSigned"

After changing this policy, I was able to install the npm package succesfully.