We would like to run pipeline job to call power shell scripts on remote windows hosts, we don’t want to use username/password. I couldn’t get openssh to work, what other options we have for windows authentication.
What was going wrong with openssh? It’s definitely the best method. I don’t know of any other auth methods that would work.
1 Like
Maybe a bit late, but:
You can use PSExec.exe from [
PsTools - Sysinternals
](PsTools - Sysinternals | Microsoft Learn)
withCredentials([usernamePassword(credentialsId: CREDENTIALS, passwordVariable: 'CREDS_P', usernameVariable: 'CREDS_U')]) {
// remoteserver: name of the remote server
// domain: the domain the win-user is running under Jenkins creds don't have that
// C:\\...\\test.ps1 full path to the script (beforehand, I use "net use" and dir() to copy the ps1-file over/create it)
writeFile file: "run.bat", text: "\"${env.WORKSPACE}\\PSTools\\PSExec.exe\" \\\\remoteserver -u domain\\" + CREDS_U + " -p " + CREDS_P + " cmd /c \"powershell C:\\...\\test.ps1\""
// PSTools are located in the subdir PSTools
// /accepteula is for agreeing to the eula to make shure it runs
bat(returnStdout: true, script: ".\\PSTools\\PSExec.exe \\\\localhost -u domain\\%CREDS_U% -p %CREDS_P% /accepteula cmd /c \"${env.WORKSPACE}\\run.bat\"")
}