PoshCode Archive  Artifact [9af2643a34]

Artifact 9af2643a342f14b2a849b7279a390c5c7454f5f1a094d57b3f6c6abd56d2f358:

  • File Test-Prompt.ps1 — part of check-in [b590649efa] at 2018-06-10 14:06:59 on branch trunk — Test the Prompt features (user: Anonymous size: 1544)

# encoding: ascii
# api: powershell
# title: Test-Prompt
# description: Test the Prompt features
# version: 0.1
# type: script
# author: Anonymous
# license: CC0
# x-poshcode-id: 605
# x-archived: 2016-04-17T02:03:16
# x-published: 2009-09-26T01:13:00
#
#
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(new System.Management.Automation.Host.ChoiceDescription "&Yes","Choose me!"),
(new 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``1[[System.Management.Automation.Host.FieldDescription]]"

$f = new 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 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 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