【问题标题】:Powershell (pwsh) does not take command-line arguments?Powershell(pwsh)不接受命令行参数?
【发布时间】:2020-01-17 18:13:13
【问题描述】:

根据pwsh documentation,我应该能够传递命令行参数,例如 -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

这是怎么回事???

【问题讨论】:

  • 你用的是什么外壳? -h-help-? 都为我打开了 pwsh 帮助文本。
  • 此行为在 Windows cmd 提示符和 Powershell 提示符下都发生

标签: powershell-core


【解决方案1】:

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

要从 Powershell 中访问帮助文档,请输入命令“Get-Help”(或别名“help”),然后输入您需要帮助的命令的名称。例如:

Get-Help Test-Connection

希望这会有所帮助!

【讨论】:

  • 对不起,这不是我的问题。我已经编辑了我的原始帖子以使其更加清晰 - 在我的计算机上,pwsh 命令无法识别任何参数。
【解决方案2】:

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

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

解决方法:卸载RC版powershell 7

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

我注意到安装版本 7 并没有卸载 RC,所以我必须明确卸载。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 2013-03-15
    • 2017-07-19
    • 1970-01-01
    相关资源
    最近更新 更多