win10 PowerShellw does not recognize commands such as npm/yarn/pnpm/cnpm/nvm, but the CMD window does

After following the nvm, npm, pnpm, yarn and other commands globally in win10 powerShell, I found that the powerShell window does not recognize these commands, but the DOS cmd window does.

#Run power shell 
set-executionpolicy remotesigned as administrator

Follow the prompts, enter A and press Enter

Return to pnpm -v again and execute successfully.

But some colleagues said no, it turns out he is not a supervisor

Set-ExecutionPolicy -Scope CurrentUser

That's it. If it doesn't work, just enter y and try.

What’s the purpose of naming it that way?

See specifically: About Execution Policies - PowerShell | Microsoft Learn

PowerShell execution strategy

These policies are enforced on Windows platforms only. The PowerShell execution policy looks like this:

Unrestricted

  • The default execution policy for non-Windows computers and cannot be changed.

  • Unsigned scripts can be run. There is a risk of running malicious scripts.

  • Warn users before running scripts and configuration files that do not come from the local intranet zone.

AllSigned

  • The script can be run.

  • Require all scripts and configuration files to be signed by a trusted publisher, including scripts written on the local machine.

  • You are prompted before running the script from publishers that have not been classified as trusted or untrusted.

  • Risk of running signed but malicious scripts.

Bypass

  • No actions are blocked, and there are no warnings or prompts.

  • This execution policy applies to configurations where PowerShell scripts are built into a larger application, or where PowerShell is the basis of a program with its own security model.

Default

  • Set the default execution policy.

  • Restricted Applicable to Windows clients.

  • RemoteSigned for Windows servers.

RemoteSigned

  • The default execution policy for Windows Server computers.

  • The script can be run.

  • Requires digital signatures from trusted publishers for scripts and configuration files downloaded from the Internet, including e-mail and instant messaging programs.

  • Digital signatures are not required on scripts written on the local computer and not downloaded from the Internet.

  • If the script is not blocked (for example, using a cmdlet), run the unsigned Unblock-File script downloaded from the Internet.

  • Risk of running unsigned scripts from sources outside the Internet, as well as signed scripts that may be malicious.

Restricted

  • The default execution policy for Windows client computers.

  • Single commands are allowed, but scripts are not.

  • Blocks all script files from running, including formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell configuration files (.ps1).

Undefined

  • There is no execution policy set in the current scope.

  • If the execution policy in all scopes is Undefined, the effective execution policies are Restricted for Windows clients and RemoteSigned for Windows Servers.

Reference article:

pnpm uses   https://www.cnblogs.com/ziyue7575/p/16826240.html

The solution to the failure of executing set-ExecutionPolicy RemoteSigned. The  solution to the failure of execution of set-ExecutionPolicy RemoteSigned_Mr. Xiao Liu’s very hard-working blog-CSDN blog

Reprint the article " win10 PowerShellw does not recognize npm/yarn/pnpm/cnpm/nvm and other commands, but the CMD window can ",
please indicate the source: win10 PowerShellw does not recognize npm/yarn/pnpm/cnpm/nvm and other commands, but the CMD window does But it can - windows, win10, win8, win7, win, windows system, Microsoft system, window system - Zhou Junjun's personal website

Guess you like

Origin blog.csdn.net/u012244479/article/details/130918522