Display Message Box Dialog

by Nov 9, 2015

PowerShell is console-based, but sometimes it would be nice to add some simple dialogs. Here is a function called Show-MessageBox that can display all kinds of standard message boxes and comes with IntelliSense for parameters:

#requires -Version 2

Add-Type -AssemblyName PresentationFramework
function Show-MessageBox
        $Title = 'Windows PowerShell',
        $Buttons = 'YesNo',
        $Icon = 'Information'
    [System.Windows.MessageBox]::Show($Prompt, $Title, $Buttons, $Icon)

$result = Show-MessageBox -Prompt 'Rebooting.' -Buttons OKCancel -Icon Exclamation

if ($result -eq 'OK')
  Restart-Computer -Force -WhatIf

Twitter This Tip! ReTweet this Tip!