An Easy InputBox

All user input and output normally occurs inside the PowerShell console. Simply access the .NET framework directly if you'd like to get back the same dialogs VBScript scripters are using. Here is the old-fashioned InputBox:

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "$env:username")
"Your name is $name"

And here is your MsgBox:

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$result = [Microsoft.VisualBasic.Interaction]::MsgBox( `
"Do you agree?", 'YesNoCancel,Question', "Respond please")

switch ($result) {
'Yes' { "Ah good" }
'No' { "Sorry to hear that" }
'Cancel' { "Bye..." }
}

Posted Mar 27 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.