I am trying to run powershell script on a remote computer (Windows 2008 Server R2). The following code works fine when executed directly from powershell. (Ie everything is configured correctly, WinRM services are started, hosts trust each other, login is correct ...)
However, when I execute the same code from a Jenkins instance (running on the same machine where I tested), I get a PSSessionStateBroken connection failure . (Do not post the full error because it is in German on my machine.)
I suppose this means that Jenkins uses powershell differently or has different powershell / winrm settings or insufficient privileges. Any ideas?
$computer = "<some ip>" $user = "Administrator" $password = "<secretpassword>" $securepassword = ConvertTo-SecureString -String $password -AsPlainText -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $securepassword Invoke-Command -ComputerName $computer -ScriptBlock { Get-ChildItem C:\ } -Credential $cred
Edit: I was able to fix this by starting the jenkins service as an administrator. Works for me but doesn't feel good ...
source share