Typical ways to obtain access to windows and controls (please note that you must run powershell As Administrator if you are not domain admin or the settings don't allow you to):

Get a window by its process name:

Get-UIAWindow -ProcessName $processname | Get-UIAButton -Name $btnName | Invoke-UIAButtonClick;
Get-UIAWindow -pn $processname | Get-UIAButton -Name $btnName | Invoke-UIAButtonClick;
Get-UIAWindow -ProcessName $processname | Get-UIAMenuItem -Name File | Invoke-UIAMenuItemClick | Get-UIAMenuItem -Name Open... | Invoke-UIAMenuItemClick | Get-UIAChildWindow -Name 'Open File'

Get a window by its process Id:

Get-UIAWindow -ProcessId (Get-Process -Name mmc).Id
Get-UIAWindow -pid (Get-Process -Name mmc).Id

Get a window from process:

Start-Process calc -PassThru | Get-UIAWindow
Get-UIAWindow -Process (Get-Process -Name mmc)
Get-UIAWindow -p (Get-Process -Name mmc)

Get a window by window title:

Get-UIAWindow -Name $windowTitle | Get-UIAChildWindow | Get-UIATextBox -AutomationID ServerBox | Set-UIATextBoxText -Text "text";

Get a window by window handle:

Get-UIAWindowFromHandle -Handle 123456

Get the active window (it's recommended to run your script in a minimized window):


Last edited Mar 11, 2012 at 3:12 PM by xinliu, version 20


behradz Feb 29, 2012 at 6:28 AM 
Is there any when to get UIA-Window by process ID or Main Window hwnd?