我有一个winrm脚本,我正在使用Jenkins从windows slave执行这个脚本到远程机器,并且我已经在windows从站c:\ windows \ system32文件夹中复制了psexec.exe,pservice.exe 。但是,当我从詹金斯执行下面的脚本,它给出了Winrm脚本不能通过Jenkins执行
PsExec.exe一个错误:术语“PsExec.exe”不被识别为一个 cmdlet,函数的名称,脚本文件或可操作的程序。检查名称的拼写,或者如果包含路径,请确认路径 是正确的,然后重试。在 C:\ Users \ cicd \ AppData \ Local \ Temp \ hudson5218849623344511653.ps1:66 char:7 + PsExec.exe \ $ computer -accepteula -s C:\ Windows \ System32 \ winrm.cmd qc -qu。 .. + ~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(PsExec.exe:字符串)[],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从属powershell窗口执行脚本时,它工作正常。但从jenkins它给出了错误。
有没有人有任何想法我为什么会得到那个错误?
我更换
PsExec.exe
尝试以上方法。由于psexec文件已存在于system32文件夹中,因此即使正在从不同的目录运行该文件。 – Shimith我试过以上方法。由于psexec文件已经存在于system32文件夹中,所以即使从不同的目录运行它,也需要它。但是脚本仍然会给出错误。但是当我从奴隶机器运行脚本时,它运行时没有任何问题 – Shimith
@Shimith你是否尝试过使用full脚本中可执行文件的名称? – ConnorLSW