Chocolatey 命令用于验证已安装的软件包,不受 Chocolatey 1/2 版本的影响。

huangapple go评论58阅读模式
英文:

Chocolatey command to verify installed package regardless of chocolatey 1/2 version

问题

Chocolatey重新设计了“choco list”命令。从版本2.0开始,不再接受--lo(=本地)参数,每次调用都被视为针对本地软件包。

  • Chocolatey 1.1:它列出了本地软件包("1个软件包已安装。")
  • Chocolatey 2.0:错误("无效的参数--lo。该参数已从列表命令中删除,无法使用。")

choco list -e procmon

  • Chocolatey 1.1:它列出了远程软件包("找到1个软件包。")
  • Chocolatey 2.0:它列出了本地软件包("1个软件包已安装。")

我使用PowerShell脚本来维护各种Chocolatey版本的1000台计算机。我需要一个通用的命令来查找是否安装了Chocolatey软件包。无论Chocolatey的版本如何,都能正常工作。如何实现?

英文:

Chocolatey reworked "choco list" command. Since version 2.0 it no more accepts --lo (=local) argument and every call is considered against local packages.

choco list --lo -e procmon

  • Chocolatey 1.1: it lists local package ("1 packages installed.")
  • Chocolatey 2.0: error ("Invalid argument --lo. This argument has been removed from the list command and cannot be used.")

choco list -e procmon

  • Chocolatey 1.1: it lists remote package ("1 packages found.")
  • Chocolatey 2.0: it lists local package ("1 packages installed.")

I use PowerShell scripts to maintain 1000 machines with various chocolatey versions. I need universal command to find if chocolatey package is installed. The command which works regardless on chocolatey version. How to do it?

答案1

得分: 2

在Chocolatey 1.*和2.*中,这应该可以工作:

choco list --lo --limit-output -e procmon

在这种情况下,--limit-output(或 -r)限制输出为机器可读的分隔格式(我建议在PowerShell中解析时使用这种方式,而不是匹配“x package found”)。您可以类似以下方式做:

$Result = choco list --lo -r -e vscode | ConvertFrom-Csv -delimiter "|" -Header Id,Version

或者,只需检查包是否已安装:

if (choco list --lo -r -e procmon) {
  Write-Host "'procmon' 已安装"
}
英文:

In both Chocolatey 1.* and 2.*, this should work:

choco list --lo --limit-output -e procmon

The --limit-output (or -r) in this case is restricting the output to a machine-readable delimited format (which I'd suggest using when parsing in PowerShell anyway, rather than matching on "x package found"). You could do something similar to the following:

$Result = choco list --lo -r -e vscode | ConvertFrom-Csv -delimiter "|" -Header Id,Version

Or, to just check that a package is installed:

if (choco list --lo -r -e procmon) {
  Write-Host "'procmon' is installed"
}

huangapple
  • 本文由 发表于 2023年6月26日 16:24:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定