forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromptExamples.ps1
41 lines (30 loc) · 1.72 KB
/
PromptExamples.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<# ------ Input Prompts ------ #>
$fields = @(
New-Object "System.Management.Automation.Host.FieldDescription" "Input"
New-Object "System.Management.Automation.Host.FieldDescription" "Input List"
)
$fields[1].SetParameterType([int[]])
$host.UI.Prompt("Caption", "Message", $fields)
Get-Credential
Get-Credential -Message "Test!"
Get-Credential -UserName "myuser" -Message "Password stealer"
$host.UI.PromptForCredential("Caption", "Message", $null, $null, [System.Management.Automation.PSCredentialTypes]::Default, [System.Management.Automation.PSCredentialUIOptions]::Default)
$host.UI.PromptForCredential("Caption", "Message", "testuser", $null, [System.Management.Automation.PSCredentialTypes]::Default, [System.Management.Automation.PSCredentialUIOptions]::Default)
Read-Host -AsSecureString
Read-Host -Prompt "Enter a secure string" -AsSecureString
$field = New-Object "System.Management.Automation.Host.FieldDescription" "SecureString"
$field.SetParameterType([SecureString])
$host.UI.Prompt("Caption", "Message", $field)
$field = New-Object "System.Management.Automation.Host.FieldDescription" "PSCredential"
$field.SetParameterType([PSCredential])
$host.UI.Prompt("Caption", "Message", $field)
<# ------ Choice Prompts ------ #>
$choices = @(
New-Object "System.Management.Automation.Host.ChoiceDescription" "&Apple", "Apple"
New-Object "System.Management.Automation.Host.ChoiceDescription" "&Banana", "Banana"
New-Object "System.Management.Automation.Host.ChoiceDescription" "&Orange", "Orange"
)
# Single-choice prompt
$host.UI.PromptForChoice("Choose a fruit", "You may choose one", $choices, 1)
# Multi-choice prompt
$host.UI.PromptForChoice("Choose a fruit", "You may choose more than one", $choices, [int[]]@(0, 2))