Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's MsgBox Function

Windows PowerShell

Definition: Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.


Windows PowerShell does not posses built-in methods for displaying message boxes. However, it’s very easy to use the New-Object Cmdlet to create an instance of the Windows Script Host (WSH) Shell object; from there you can use the WSH Popup method to display a message box. The following example first uses New-Object (and the -comobject parameter) to create an instance of the Wscript.Shell object. In the second command, the WSH Popup method is used to display a message box, with the resulting action (that is, the value of the button the user clicked to dismiss the message box) stored in the variable $b:

$a = new-object -comobject wscript.shell
$b = $a.popup("This is a test",0,"Test Message Box",1)

For more information on the parameters used when displaying the message box see the Windows Script Host Language Reference.

Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft