felixrieseberg / npm-windows-upgrade

:rocket: Upgrade npm on Windows
MIT License
2.53k stars 149 forks source link

"Scripts cannot be executed on this system." on pwsh 7 if process scope is not Unrestricted #173

Open Fred-Vatin opened 3 years ago

Fred-Vatin commented 3 years ago

Here is my config

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I only installed PowerShell-7.1.3-win-x64.msi.

Unrestricted current user failed

I have set both local machine and current user to unrestricted but it keeps returning the error message Scripts cannot be executed on this system. It’s been fixed when I ran the Set-ExecutionPolicy Unrestricted -Force -scope Process command.

Working Policy on my system

Then I tried to run the npm-windows-upgrade command with this policy only :

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    Unrestricted
  CurrentUser    RemoteSigned
 LocalMachine    RemoteSigned

And it worked 🎉. The process scope is only applied during session. It is reset to undefined for new session.

I didn’t try every combination but for Powershell local users, I guess it’s a common setting for pwsh 7.

I guess this needs to be mentionned for users who could face this issue.