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
Coordinator
Feb 28 at 3:08 PM
Hi alangelier61,
the PowerShell Remoting session works as a service and it's 'session 0'. In the session 0 there's no normal desktop and any used-side activity is limited. Moreover, the Microsoft UI Automaiton framework, the basement of UIAutomation PowerShell, has its own restriction that it doesn't work in general with what the user can't see. It's a consequence of the fact that Microsoft UI Automation is firstly an accessibility framework and it doesn't make sense to access anything the user can't access, and only the second goal initially was testing automation.

To be honest, a bit of functionality could work in session 0, for example, those parameters that initiate usage of Win32 API (the -Win32 parameter, for example). Anyway, it's not a good idea to rely on part of functionality.
The way automators use more often is to use 1) RemoteApp or 2) autologon session with a script being run automatically