-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest-Choice.ps1
More file actions
80 lines (76 loc) · 3.3 KB
/
Request-Choice.ps1
File metadata and controls
80 lines (76 loc) · 3.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Function Request-Choice
{
Param
(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[ValidateSet('AbortRetryIgnore', 'CancelTryAgainContinue', 'OkCancel', 'RetryCancel', 'YesNo', 'YesNoCancel')]
[string]
$Type,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
[ValidateNotNullOrEmpty()]
[string]
$Title,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 2)]
[ValidateNotNullOrEmpty()]
[string]
$Text,
[Parameter(ValueFromPipelineByPropertyName = $true, Position = 3)]
[ValidateRange(1,3)]
[int]
$DefaultItem = 1
)
Process
{
# Reset stuff
$SelectedItem = $DefaultItem - 1
$OptionList = @()
$Result = $null
# Start
Switch ($Type)
{
'AbortRetryIgnore'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Abort','Aborts the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Retry','Retries the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Ignore','Ignores the operation')
}
'CancelTryAgainContinue'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Cancel','Cancels the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Try Again','Retries the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('C&ontinue','Continues the operation')
}
'OkCancel'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&OK','Accepts the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Cancel','Cancels the operation')
}
'RetryCancel'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Retry','Retries the operation')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Cancel','Cancels the operation')
}
'YesNo'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Yes','Replies with Yes')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&No','Replies with No')
}
'YesNoCancel'
{
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Yes','Replies with Yes')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&No','Replies with No')
$OptionList += New-Object -TypeName System.Management.Automation.Host.ChoiceDescription ('&Cancel','Cancels the operation')
}
Default
{
Throw ('Can''t match the provided type {0}' -f $Type)
}
}
$Options = [System.Management.Automation.Host.ChoiceDescription[]] $OptionList
$Result = $host.UI.PromptForChoice($Title, $Text, $Options, $SelectedItem)
If ($Result -ne $null)
{
$Options[$Result].Label.Replace('&','')
}
}
}