I am trying to execute an automated test on a remote server. In order for the test to run, the user has to be authenticated into a system using a desktop application. Basically after you start the desktop application, a GUI window is displayed and then you enter a password and hit enter. After the user is authenticated, then the automated test can start.
I have written a Powershell script then when it runs, it can start the GUI application, enter the password, press ok, and the user gets authenticated. It runs without any problems if I am logged into the machine via an active remote desktop connection.
$password = "password"
& 'C:\Windows\GuiPassword.exe'
Start-Sleep -Seconds 60
$wshell = New-Object -ComObject wscript.shell;
write-output "Focusing on the window"
$wshell.AppActivate('Gui Password')
Sleep 2
write-output "Entering the password string"
write-output "$wshell.SendKeys('$password')"
$wshell.SendKeys("$password")
$wshell.AppActivate('Gui Password')
Sleep 2
write-output "Entering Enter key"
$wshell.SendKeys('{ENTER}')
Sleep 10`
I know this runs because I see it entering the password and then hitting the ok button while being logged into via Remote Desktop Connection. Also it displays "true" in Powershell ISE when it gets to the AppActivate calls
Now I have tried to execute this script remotely via a PS Session from another machine. Remoting is turned on and configured correctly. I see the script executing but it is unable to find the GUI window because I see "false" strings being displayed on the screen on the remote machine where I am executing it from. This is the powershell script that I am executing from a different machine. Assume that above script is saved as a powershell script called GUILogin.ps1 :
$tpassword = "password"
$secPasswd = ConvertTo-SecureString -AsPlainText -Force -String $tpassword
$myCreds = New-Object System.Management.Automation.PSCredential -argumentlist "REMOTESYSTEMUSERID", $secPasswd
$ps_Opt = New-PSSessionOption -IdleTimeout 43199999
$TargetSession = New-PSSession -ComputerName RemoteSystemname -Credential $myCreds -ConfigurationName RemoteExecution -SessionOption $ps_Opt
Write-Output "Session created"
Invoke-Command -Session $TargetSession -Command {D:\Temp\GUILogin.ps1}
Remove-PSSession $TargetSession
I am guessing it can't find it because it is a desktop application and requires an active desktop. Is that right? Can you please suggest what I can do so it can be found via the PS Session ?
Thank you