"The term 'choco' is not recognized" 远程执行命令时

"The term 'choco' is not recognized" when executing command remotely

我正在尝试使用 Powershell 远程安装 Chocolatey 和 Choco 包。我可以使用以下方法远程安装 Chocolatey(我的 txt 文件包含一个服务器):

$ComputerList = "C:\temp\DataDogServers.txt"
$Computers = Get-Content -Path $ComputerList

Invoke-Command -ComputerName $Computers -ScriptBlock {
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}

然后当我尝试执行远程 choco 命令时,它抛回 The term 'choco' is not recognized as the name of a cmdlet, function, script file, or operable program. 我确认 运行 choco 在远程服务器上正常工作。

它可能已安装但未更新当前会话的路径。使用 choco.exe 的完全限定路径,或 update/reload 您的 PATH 环境变量。