PoshCode Archive  Artifact Content

Artifact 14f1f3d1e494f71804156a8ede9a2248abdf8592c999caaaa498f41218a302ea:

  • File Test-Prompt.ps1 — part of check-in [15ed6e9897] at 2018-06-10 13:02:17 on branch trunk — Test the Prompt features (user: Damien Ryan size: 1607)

# encoding: ascii
# api: powershell
# title: Test-Prompt
# description: Test the Prompt features
# version: 0.1
# type: script
# author: Damien Ryan
# license: CC0
# x-poshcode-id: 1870
# x-derived-from-id: 1886
# x-archived: 2016-04-17T04:25:30
# x-published: 2011-05-24T12:14:00
#
#
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Choose me!"),
(New-Object System.Management.Automation.Host.ChoiceDescription "&No","Pick me!"))

$Answer = $host.ui.PromptForChoice('Caption',"Message",$choices,(1))

Write-Output $Answer

$fields = new-object "System.Collections.ObjectModel.Collection"[[System.Management.Automation.Host.FieldDescription]]"

$f = New-Object System.Management.Automation.Host.FieldDescription "String Field"
$f.HelpMessage  = "This is the help for the first field"
$f.DefaultValue = "Field1"
$f.Label = "&Any Text"

$fields.Add($f)

$f = New-Object System.Management.Automation.Host.FieldDescription "Secure String"
$f.SetparameterType( [System.Security.SecureString] )
$f.HelpMessage  = "You will get a password input with **** instead of characters"
$f.DefaultValue = "Password"
$f.Label = "&Password"

$fields.Add($f)

$f = New-Object System.Management.Automation.Host.FieldDescription "Numeric Value"
$f.SetparameterType( [int] )
$f.DefaultValue = "42"
$f.HelpMessage  = "You need to type a number, or it will re-prompt"
$f.Label = "&Number"

$fields.Add($f)

$results = $Host.UI.Prompt( "Caption", "Message", $fields )

Write-Output $results