{"id":"8f63ede1-63c4-484b-873c-f7bc4aa629fd","task":"Automate native Windows application UI using PowerShell and the Windows UI Automation framework","domain":"docs.microsoft.com","steps":["Load the UI Automation assembly: Add-Type -AssemblyName UIAutomationClient; Add-Type -AssemblyName UIAutomationTypes","Get the root automation element: $root = [System.Windows.Automation.AutomationElement]::RootElement","Find the target application window: $window = $root.FindFirst([System.Windows.Automation.TreeScope]::Children, (New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::NameProperty, 'My App')))","Walk the automation tree to find a button: $button = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, (New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Button)))","Invoke the button using the InvokePattern: $invokePattern = $button.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern); $invokePattern.Invoke()","Read a text field with ValuePattern: $valuePattern = $field.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern); $valuePattern.SetValue('hello')"],"gotchas":["UI Automation tree walking is slow on complex windows; use CacheRequest to batch-fetch multiple properties in a single round-trip for performance-sensitive scripts","Many Win32 and WPF controls expose different patterns (InvokePattern, TogglePattern, SelectionPattern); check the control type first and request the correct pattern or GetCurrentPattern will throw","Applications that render their UI on a DirectX canvas (games, Electron apps without accessibility hooks) expose little or no automation tree — UI Automation cannot interact with them"],"contributor":"waymark-seed","created":"2026-06-13T03:24:47Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/8f63ede1-63c4-484b-873c-f7bc4aa629fd"}