I have a winrm script and I am using Jenkins to execute this script from windows slave to remote machine and I have copied psexec.exe, pservice.exe in windows slaves c:\windows\system32 folder. But when I execute the below script from jenkins it gives an error that
PsExec.exe : The term 'PsExec.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At 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:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException**
Code:
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}
}
}
}
When I execute the script from windows slaves powershell window it works fine. but from jenkins it gives the error.
Does anyone have any idea why am I getting that error ?