forked from bcdady/MyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowMsgBox.ps1
172 lines (150 loc) · 5.91 KB
/
ShowMsgBox.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#requires -Version 2
<#
.SYNOPSIS
Shows a graphical message box, with various prompt types available.
.DESCRIPTION
Emulates the Visual Basic MsgBox function. It takes four parameters, of which only the prompt is mandatory
.INPUTS
The parameters are:-
Prompt (mandatory):
Text string that you wish to display
Title (optional):
The title that appears on the message box
Icon (optional). Available options are:
Information, Question, Critical, Exclamation (not case sensitive)
BoxType (optional). Available options are:
OKOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel (not case sensitive)
DefaultButton (optional). Available options are:
1, 2, 3
.OUTPUTS
Microsoft.VisualBasic.MsgBoxResult
.EXAMPLE
C:\PS> Show-MsgBox Hello
Shows a popup message with the text "Hello", and the default box, icon and defaultbutton settings.
.EXAMPLE
C:\PS> Show-MsgBox -Prompt "This is the prompt" -Title "This Is The Title" -Icon Critical -BoxType YesNo -DefaultButton 2
Shows a popup with the parameter as supplied.
.LINK
http://gallery.technet.microsoft.com/scriptcenter/Powershell-Show-MsgBox-982f6906
.LINK
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxresult.aspx
.LINK
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxstyle.aspx
.NOTES
By BigTeddy August 24, 2011
http://social.technet.microsoft.com/profile/bigteddy/.
#>
Write-Verbose -Message 'Declaring function Show-MsgBox'
function Show-MsgBox
{
<#
.SYNOPSIS
Shows a graphical message box, with various prompt types available.
.DESCRIPTION
Emulates the Visual Basic MsgBox function. It takes four parameters, of which only the prompt is mandatory
.PARAMETER Message
Text string that you wish to display in the message (dialog) box windows
.PARAMETER Title
The title that appears on the message box
.PARAMETER Icon
Available options are:
Information, Question, Critical, Exclamation (not case sensitive)
.PARAMETER BoxType
Available options are:
OKOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel (not case sensitive)
DefaultButton (optional). Available options are:
1, 2, 3
.EXAMPLE
.\PS> Show-MsgBox Hello
Shows a popup message with the text "Hello", and the default box, icon and defaultbutton settings.
.EXAMPLE
.\PS> Show-MsgBox -Message "This is the Message" -Title "This Is The Title" -Icon Critical -BoxType YesNo -DefaultButton 2
Shows a popup with the parameter as supplied.
.NOTES
NAME : Show-MsgBox
CREATED : August 24, 2011
AUTHOR : BigTeddy (http://social.technet.microsoft.com/profile/bigteddy/)
VERSION : 1.1.0
LAST UPDATED: 12/3/2015
BY (EDITOR) : Bryan Dady (@bcdady)
.LINK
http://gallery.technet.microsoft.com/scriptcenter/Powershell-Show-MsgBox-982f6906
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxresult.aspx
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.msgboxstyle.aspx
http://social.technet.microsoft.com/profile/bigteddy/.
.INPUTS
INPUTS
.OUTPUTS
OUTPUTS
#>
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory = $true)] [string]$Message,
[Parameter(Position = 1, Mandatory = $false)] [string]$Title = '',
[Parameter(Position = 2, Mandatory = $false)] [ValidateSet('Information', 'Question', 'Critical', 'Exclamation')] [string]$Icon = 'Information',
[Parameter(Position = 3, Mandatory = $false)] [ValidateSet('OKOnly', 'OKCancel', 'AbortRetryIgnore', 'YesNoCancel', 'YesNo', 'RetryCancel')] [string]$BoxType = 'OkOnly',
[Parameter(Position = 4, Mandatory = $false)] [ValidateSet(1,2,3)] [int]$DefaultButton = 1
)
$null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
switch ($Icon) {
'Question'
{
$vb_icon = [microsoft.visualbasic.msgboxstyle]::Question
}
'Critical'
{
$vb_icon = [microsoft.visualbasic.msgboxstyle]::Critical
}
'Exclamation'
{
$vb_icon = [microsoft.visualbasic.msgboxstyle]::Exclamation
}
'Information'
{
$vb_icon = [microsoft.visualbasic.msgboxstyle]::Information
}
}
switch ($BoxType) {
'OKOnly'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::OKOnly
}
'OKCancel'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::OkCancel
}
'AbortRetryIgnore'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::AbortRetryIgnore
}
'YesNoCancel'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNoCancel
}
'YesNo'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::YesNo
}
'RetryCancel'
{
$vb_box = [microsoft.visualbasic.msgboxstyle]::RetryCancel
}
}
switch ($DefaultButton) {
1
{
$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton1
}
2
{
$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton2
}
3
{
$vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::DefaultButton3
}
}
$popuptype = $vb_icon -bor $vb_box -bor $vb_defaultbutton
$ans = [Microsoft.VisualBasic.Interaction]::MsgBox($Message,$popuptype,$Title)
return $ans
} #end function