Reputation: 91
End Goal : To configure a jenkins job to run a automation script on an windows desktop app in windows active session, am using Jenkins + Psexec command to achieve this goal.
Code that i used is below :
$sessionInfo = & psexec \\$remoteMachine -s -i query session
Write-Output "session info: "+ $sessionInfo
$sessionInfo | Where-Object { $_ -match "^\s*rdp" } | ForEach-Object {
$fields = $_ -split '\s{2,}'
if ($fields.Length -ge 4 -and $fields[3] -eq 'Active') {
$fields[2]
$sessionId = $fields[2] # Output the session ID
Write-Output "inner loop-Session id for current open session : "+ $sessionId
}
}
psexec \\$remoteMachine -s -i $sessionId powershell.exe -ExecutionPolicy Bypass -Command "& {C:\bat-automatic\PS_trail.ps1 -SessID '$sessionId'}"
The above script works completely fine by triggering the automation script in remote machine when i run it from the host powershell app, but when i tried the same with the Jenkins job in the powershell build step, the below command
& psexec \\$remoteMachine -s -i query session
console output of jenkins looks like below :
Connecting to <remoteMahcine1>...
Starting PSEXESVC service on <remoteMahcine1>...
Copying authentication key to <remoteMahcine1>...
Connecting with PsExec service on <remoteMahcine1>...
Starting query on <remoteMahcine1>...
SESSIONNAME USERNAME ID STATE TYPE DEVICE
query exited on <remoteMahcine1> with error code 1.
so couldn't able to trigger the automation script in an active windows session. In order to achieve this, could anyone point out Where am i making mistake ?
Upvotes: 0
Views: 68
Reputation: 2548
If I had to guess your Jenkins user doesn't have enough permissions. According to the doc:
A user can always query the session to which the user is currently logged on. To query other sessions, the user must have special access permission.
You can try two things:
Upvotes: 0