Handling Results
When a PoshUI Wizard completes, it returns the data collected from the user back to your PowerShell script. Understanding how to handle these results is key to building successful automation.
Return Value (Simple Mode)
In Simple Mode (without -ScriptBody), Show-PoshUIWizard returns a hashtable containing the values from all input controls.
Keys and Values
The keys in the hashtable correspond to the -Name parameter you provided when adding each control.
$result = Show-PoshUIWizard
if ($result) {
# Access by key name
$server = $result.ServerName
$env = $result.Environment
Write-Host "Proceeding with deployment to $server in $env..."
}Handling Cancellation
If the user clicks the Cancel button or closes the window using the X, Show-PoshUIWizard returns $null.
DANGER
Always check for $null before attempting to access properties on the result object.
$result = Show-PoshUIWizard
if ($null -eq $result) {
Write-Warning "User cancelled. Aborting operation."
exit
}Data Types
PoshUI preserves the appropriate PowerShell data types for your results:
| Control Type | PowerShell Return Type |
|---|---|
| TextBox, MultiLine | [string] |
| Password | [SecureString] |
| Checkbox, Toggle | [bool] / [switch] |
| Numeric | [double] |
| Date | [DateTime] |
| Dropdown (Single) | [string] |
| ListBox (Multi) | [string[]] |
| FilePath, FolderPath | [string] (Full Path) |
Results in Live Execution Mode
In Live Execution Mode (using -ScriptBody), the behavior is different:
- Variables are Injected: All results are available during execution as variables (e.g.,
$ServerName). - Return Value is Status: The value returned by
Show-PoshUIWizardindicates if the window was closed normally or cancelled, but since the script has already run, this is usually less important.
TIP
If you need to pass data from your ScriptBody back to the calling script, consider writing it to a file or using global variables (though file-based state is recommended for reliability).
Next: About Dashboards
