Beta 42

Research and Development


PowerShell - Showing MsgBox

Ever wanted to display a dialog box from PowerShell rather than spitting out console text?

Try the following function:

function Show-MsgBox {
    [String]$Title = 'Message',   
    $Icon = 'YesNo,Information'

  Add-Type -AssemblyName 'Microsoft.VisualBasic' 
  [Microsoft.VisualBasic.Interaction]::MsgBox($text, $icon, $title)

It is really easy to use: simply tell it what to display:

Show-MsgBox -Text 'Reboot system?' -Title 'Warning' -Icon 'YesNoCancel,Question'

And this makes it a useful function:

$result = Show-MsgBox -Text 'Reboot system?' -Title 'Warning' -Icon 'YesNoCancel,Question'
if ($result -eq 'Yes') {
  Restart-Computer -Force