【发布时间】:2017-11-13 17:52:03
【问题描述】:
我有一个 winrm 脚本,我正在使用 Jenkins 将这个脚本从 windows slave 执行到远程机器,并且我已将 psexec.exe、pservice.exe 复制到 windows slaves c:\windows\system32 文件夹中。但是当我从詹金斯执行下面的脚本时,它给出了一个错误,
PsExec.exe : 术语“PsExec.exe”未被识别为 cmdlet、函数、脚本文件或可运行的程序。检查 名称的拼写,或者如果包含路径,请验证路径 是正确的,然后再试一次。在 C:\Users\cicd\AppData\Local\Temp\hudson5218849623344511653.ps1:66 字符:7 + PsExec.exe \$computer -accepteula -s C:\Windows\System32\winrm.cmd qc -qu ... + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (PsExec.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException**
代码:
foreach ($computer in $hosts) {
$result = winrm id -r:$computer 2> $null
if ($lastExitCode -eq 0) {
Write-Host "WinRM already enabled on" $computer "..." -ForegroundColor green
} else {
Write-Host "Enabling WinRM on" $computer "..." -ForegroundColor red
PsExec.exe \\$computer -accepteula -s C:\Windows\System32\winrm.cmd qc -quiet
if ($LastExitCode -eq 0) {
PsService.exe \\$computer -accepteula restart WinRM
$result = winrm id -r:$computer 2>$null
if ($LastExitCode -eq 0) {Write-Host "WinRM successfully enabled!" -ForegroundColor green}
else {Write-Host "WinRM not enabled!" -ForegroundColor red}
}
}
}
当我从 windows slaves powershell 窗口执行脚本时,它工作正常。但从詹金斯它给出了错误。
有人知道我为什么会收到这个错误吗?
【问题讨论】:
标签: windows powershell jenkins