我有一個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