UIautomation: cannot contol GUI on a remote PC

Feb 9 at 5:28 PM
I am trying to control on my local PC a remote application that is running on a remote PC.

The following code is working when controlling the same application locally.

Get-UiaWindow -Class 'Window' -Name 'Archiver Collector Tool' |Get-UiaButton -AutomationId '_startButton' -Class 'Button' -Name 'Start'| Invoke-UiaButtonClick

But when trying to run it through invoke command on an open session (New-PSSession) it does not work.

Invoke-Command -Session $job {Import-Module "C:\UIAutomation\UIAutomation.dll" ; Get-UiaWindow -Class 'Window' -Name 'Archiver Collector Tool'| get-UiaButton -AutomationId '_startButton' -Class 'Button' -Name 'Start'| Get-UiaText -Class 'TextBlock' -Name 'Start'}

Following error is seen.

_Failed to get window in 5000 milliseconds by: process name: '', process Id: , window title: 'Archiver Collector Tool', automationId: '', className: 'Window'.
+ CategoryInfo          : InvalidResult: (:) [Get-UiaWindow], Exception
+ FullyQualifiedErrorId : FailedToGetWindow,UIAutomation.Commands.GetUiaWindowCommand
+ PSComputerName        : remotePC