Schematically, the Wizard cmdlets work in the typical sequence:

New-UIAWizard - creates a new wizard object, gives it the name and initial script (Start-Process of an independent wizard-application or click anywhere in the program to call an embedded wizard)

Add-UIAWizardStep - takes the wizard object through the pipeline (or the InputObject parameter), sets the name to a step and the order (not used in this version). After that ad the step to the wizard.

Remove-UIAWizardStep - removes a step from the collection

Get-UIAWizard - returns a wizard by name

Invoke-UIAWizard - start the wizard by running code in the start action, returns the wizard object.

Step-UIAWizard - performs the step given as a name. Firstly searches and waits for the condition from the parameter WaitCriteria, after that runs its step action. Returns the wizard object.

ipmo -Name $UIAmodule; # path to the module
$VerbosePreference = [System.Management.Automation.ActionPreference]::Continue;

#region Creating a wizard
Write-Host "=======================================================================================";
Write-Host "Creating a wizard`r`n";
New-UIAWizard -Name wzd -StartAction {Write-Host "starting the wizard code";} | `
	Add-UIAWizardStep -Name step1 -Order 10 -WaitCriteria @{Name='welcomePane';IsEnabled=$true} -StepAction {Write-Host "step 1 code";} | `
	Add-UIAWizardStep -Name step2 -Order 20 -WaitCriteria @{Name='I accept';IsEnabled=$false} -StepAction {Write-Host "step 2 code";} | `
	Add-UIAWizardStep -Name step3 -Order 30 -WaitCriteria @{Name='User name';IsEnabled=$true},@{Name='Organization';IsEnabled=$true} -StepAction {Write-Host "step 3";},{Write-Host "step 3 code";} | `
	Remove-UIAWizardStep -Name step2 | `
	Add-UIAWizardStep -Name step4 -Order 40 -WaitCriteria @{ControlType=Tree} -StepAction {Write-Host "step 4 code";};
#endregion Creating a wizard

#region Running the wizard
Write-Host "=======================================================================================";
Write-Host "Running the wizard`r`n";
Invoke-UIAWizard -Name wzd | `
	Step-UIAWizard -Name step1 | `
	Step-UIAWizard -Name step3 | `
	Step-UIAWizard -Name step4 | `
	Step-UIAWizard -Name step3 -Forward:$false | `
	Step-UIAWizard -Name step4;
#endregion Running the wizard	

#region How to access and/or modify the variables
Write-Host "steps";
[UIAutomation.WizardCollection]::Wizards[0].Steps
Write-Host "start action";
$wzd.StartAction
Write-Host "steps";
$wzd = Get-UIAWizard -Name "wzd";
$wzd.Steps
Write-Host "step actions";
$wzd.Steps[0].StepAction
$wzd.Steps[1].StepAction
$wzd.Steps[2].StepAction
Write-Host "fail - one step was removed in the example";
$wzd.Steps[3].StepAction
#endregion How to access and/or modify the variables

There is an easy way to create a hashtable is to pipeline a window or a control to the ConvertTo-UIASearchCriteria cmdlet.

This can be done as for one control:

Get-UIAWindow -p $procName | ConvertTo-UIASearchCriteria

Get-UIAWindow -p $procName | Get-UIAChildWindow | ConvertTo-UIASearchCriteria

Get-UIAWindow -p $procName | Get-UIAChildWindow | Get-UIAButton -Name OK | ConvertTo-UIASearchCriteria

as well for a bunch of controls:

Get-UIAWindow -p $procName | Get-UIAChildWindow | Get-UIAControlChildren | ConvertTo-UIASearchCriteria

Get-UIAWindow -p $procName | Get-UIAChildWindow | Get-UIAControlDescendants | ConvertTo-UIASearchCrite
ria

Last edited Feb 27, 2012 at 8:56 AM by xinliu, version 3

Comments

No comments yet.