Task: demonstrate return values.
Task #2: provide a field for learning the module.
Requirements: provide examples with two types of return values.
Solution: run the following code:
(Get-UIAWindow -ProcessName mmc | ` Get-UIAMenuItem -Name File | ` Invoke-UIAMenuItemClick).Current.Name
Not surprisingly, this code returned the name of the menu item selected. By default, all the cmdlets where it’s possible return the object of AutomationElement type.
However, you may change this behavior. If so, this code would return $true in success case and $false in case of an error, timeout, and cetera.
It’s needed rarely, because the if statement works well with $true/$false as well as the object/$null pair.
If you wish, you can change the code in the way:
Get-UIAWindow -ProcessName mmc | ` Get-UIAMenuItem -Name File | ` Invoke-UIAMenuItemClick -PassThru:$false;
Homework: experiment with return values. Try cmdlets one by one, which values they return with and without -PassThru.