Interactive Dialogs
We've provided a few commands to interact with the user through dialogs.

Simple Dialogs

Simple in the sense that the dialogs present the user with a short message and one or two buttons.

Alert

The Alert dialog is a way to notify the user of important information with an "OK" button.
Example: The following display a modal dialog.
1
Show-Alert -Title "SPE is great!"
Copied!
No return value.
Show Alert

Confirmation

The Confirmation dialog is a way to verify with the user before proceeding.
Example: The following displays a modal dialog with an OK or Cancel confirmation.
1
Show-Confirm -Title "Click OK to acknowledge SPE is great!"
Copied!
Button Name
Return Value
OK
yes
Cancel
no
Show Confirm

User Input

Example: The following displays an input dialog for text.
1
Show-Input "Please provide 5 characters at most" -MaxLength 5
Copied!
Button Name
Return Value
OK
< user input >
Cancel
$null
Show Input
Example: The following displays an input dialog with a error validation message.
1
$inputProps = @{
2
Prompt = "Enter a new name for the item:"
3
Validation = [Sitecore.Configuration.Settings]::ItemNameValidation
4
ErrorMessage = "'`$Input' is not a valid name."
5
MaxLength = [Sitecore.Configuration.Settings]::MaxItemNameLength
6
}
7
8
Show-Input @inputProps
Copied!
Show Input

Advanced Dialogs

Variable Settings

The Read-Variable command provides a way to prompt the user for information and then generate variables with those values.
Example: The following displays a dialog with a dropdown.
Note: The name selectedOption will result in a variable that contains the selected option.
1
$options = @{
2
"A"="a"
3
"B"="b"
4
}
5
6
$props = @{
7
Parameters = @(
8
@{Name="selectedOption"; Title="Choose an option"; Options=$options; Tooltip="Choose one."}
9
)
10
Title = "Option selector"
11
Description = "Choose the right option."
12
Width = 300
13
Height = 300
14
ShowHints = $true
15
}
16
17
Read-Variable @props
Copied!
Button Name
Return Value
OK
ok
Cancel
cancel
< variables >
< selection >
Read Variable
Supported Parameter Values
Key
Type
Description
Example
Name
string
Variable name
isSilent
Value
bool string int float datetime Item
Default value
$true
Title
string
Header or Label
"Proceed Silently
Tooltip (optional)
string
Short description or tooltip
"Check to run quietly
Tab (optional)
string
Tab title
"Simple"
Placeholder (optional)
string
Textbox placeholder
"Search text..."
Lines (optional)
int
Line count
3
Editor (optional)
string
Control type
"date time"
Domain (optional)
string
Domain name for security editor
"sitecore"
Options (optional)
string OrderedDictionary Hashtable
Data for checklist or dropdown
@{"Monday"=1;"Tuesday"=2}
Columns
int string
Number between 1 and 12 and string 'first' or 'last'
6 first
Editor Types
    bool
    check
    date
    date time
    droplist
    droptree
    email
    groupeddroplink
    groupeddroplist
    info
    item
    link
    marquee
    multilist
    multilist search
    multiple user
    multiple user role
    multiple role
    multitext
    number
    pass
    radio
    rule
    rule action
    tree
    treelist
    tristate
    time

Confirmation Choice

The Confirmation Choice dialog allows for multiple combinations like that seen with a "Yes, Yes to all, No, No to all" scenario.
Example: The following displays a modal dialog with choices.
1
Show-ModalDialog -Control "ConfirmChoice" -Parameters @{btn_0="Yes - returns btn_0"; btn_1="No - returns btn_1"; btn_2="returns btn_2"; te="Have you downloaded SPE?"; cp="Important Questions"} -Height 120 -Width 650
Copied!
Note: The hashtable keys should be incremented like btn_0, btn_1, and so on. The return value is the key name.
Button Name
Return Value
< first button >
btn_0
< second button >
btn_1
< third button >
btn_2
Show Confirm Choice

Upload

The Upload dialog provides a way to upload files from a local filesystem to the media library or server filesystem.
Example: The following displays an advanced upload dialog.
1
Receive-File (Get-Item "master:\media library\Files") -AdvancedDialog
Copied!
No return value.
Receive File

Download

The Download dialog provides a way to download files from the server to a local filesystem.
Example: The following displays a download dialog.
1
Get-Item -Path "master:\media library\Files\readme" | Send-File
Copied!
Download

Field Editor

The Field Editor dialog offers a convenient way to present the user with fields to edit.
Example: The following displays a field editor dialog.
1
Get-Item "master:\content\home" | Show-FieldEditor -Name "*" -PreserveSections
Copied!
Button Name
Return Value
OK
ok
Cancel
cancel
Show Field Editor

File Browser

The File Browser is an obvious choice when you need to upload, download, or delete files.
Example: The following displays a file browser dialog for installation packages.
1
Show-ModalDialog -HandleParameters @{
2
"h"="Create an Anti-Package";
3
"t" = "Select a package that needs an anti-package";
4
"ic"="People/16x16/box.png";
5
"ok"="Pick";
6
"ask"="";
7
"path"= "packPath:$SitecorePackageFolder";
8
"mask"="*.zip";
9
} -Control "Installer.Browse"
Copied!
Button Name
Return Value
OK
< selected file >
Cancel
undetermined
Show File Browser
Example: The following displays a simple file browser dialog.
1
Show-ModalDialog -HandleParameters @{
2
"h"="FileBrowser";
3
} -Control "FileBrowser" -Width 500
Copied!
Button Name
Return Value
OK
< selected file >
Cancel
undetermined
Show File Browser
Example: The following displays a Sheer UI control without any additional parameters.
1
Show-ModalDialog -Control "ControlPanel"
Copied!

Data List

The "Data List" is essentially a report viewer which supports custom actions, exporting, and filtering.
Example: The following displays a list view dialog with the child items under the Sitecore tree.
1
Get-Item -Path master:\* | Show-ListView -Property Name, DisplayName, ProviderPath, TemplateName, Language
Copied!
Show List View

Results

The Results dialog resembles the Console but does not provide a prompt to the user. This is useful for when logging messages.
Example: The following displays a dialog with the all the information written to the ScriptSession output buffer.
1
for($i = 0; $i -lt 10; $i++) {
2
Write-Verbose "Index = $($i)" -Verbose
3
}
4
5
Show-Result -Text
Copied!
Show Result Text
Last modified 1yr ago