Powershell (pwsh) 不接受命令行参数?



根据 pwsh 文档,我应该能够传递命令行参数,例如 -Command 或 -NoExit,但这些参数无法识别:

> pwsh -NoExit
-NoExit : The term '-NoExit' is not recognized as the name of a cmdlet, function, script file, or operable program.
...
> pwsh -NoLogo
-NoLogo : The term '-NoLogo' is not recognized as the name of a cmdlet, function, script file, or operable program.
...
> pwsh -h
-h : The term '-h' is not recognized as the name of a cmdlet, function, script file, or operable program.
...
> pwsh -Command "Write-host hello"
-Command : The term '-Command' is not recognized as the name of a cmdlet, function, script file, or operable program.
...

但这有效:

> pwsh "Write-host hello"
hello

这是怎么回事???

同样的问题,C:\Program Files\PowerShell\7\pwsh.exe

版本 7.0.0 核心,刚刚安装了从 github 下载的 msi :-(

解决方案:卸载 RC 版本的 Powershell 7

我没有解释,但是尽管运行了正确的可执行文件,但它的行为与旧的RC版本一样。

我注意到安装版本 7不会卸载 RC,所以我必须显式卸载。

删除旧的RC版本后,万岁,pwsh.exe在我的PC上尊重-NoExit和-File命令行参数;-(

根据您提供的信息,我相信您指的是使用CMD中的Powershell时的"-help"和"-command"参数。 因此,例如,如果您在CMD提示符下键入"Powershell -help",您将获得有关如何从CMD运行Powershell命令的帮助文本。

若要从 Powershell 中访问帮助文档,请键入命令"获取帮助"(或其别名"帮助"(,然后键入需要帮助的命令的名称。 例如:

Get-Help Test-Connection

希望这有帮助!

最新更新