Saturday, October 5, 2013

PowerShell Popup

To show a popup message in PowerShell, we need to create an object of wscript.shell and then call popup method with parameters.

Popup Syntax
popup("Message to be displayed",0, "popup window title", button type id + icon style id)

Example
$alert = new-object -comobject wscript.shell
$answer = $alert.popup("Do you want to delete these files?", 0,"Delete Files",4+32)
If ($answer -eq 6) {
  $alert.popup("You answered yes.")
} else {
  $alert.popup("You answered no.")
}

#Button Types 
#0 Show OK button
#1 Show OK and Cancel buttons
#2 Show Abort, Retry, and Ignore buttons
#3 Show Yes, No, and Cancel buttons
#4 Show Yes and No buttons
#5 Show Retry and Cancel buttons

#icon style
#16 Stop Icon
#32 Question Icon
#48 Exclamation Icon
#64 Information Icon

#return values of popup method
OK = 1
Cancel = 2
Abort = 3
Retry = 4
Ignore = 5
Yes = 6
No = 7

1 comment:

Anonymous said...

Appreciating the hard work you put into your blog and
detailed information you offer. It's nice to come across a
blog every once in a while that isn't the same outdated rehashed information. Wonderful read!

I've bookmarked your site and I'm including your RSS feeds to my Google account.



Feel free to surf to my web-site; how to gain weight fast ()