(MS) UIAutomation: what if -PassThru:$false


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.

Advertisements

One response

  1. This site certainly has all the information I needed about
    this subject and didn’t know who to ask.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: