If you’d like to show a default MessageBox with some buttons for the user to click, try this function:

function Show-MessageBox
{
  [CmdletBinding()]
  param
  (
    [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
    [String]
    $Text,
    
    [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
    [String]
    $Caption,
    
    [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
    [Windows.MessageBoxButton]
    $Button,
    
    [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
    [Windows.MessageBoxImage]
    $Icon
    
  )
  
  process
  {
    try
    {
      [System.Windows.MessageBox]::Show($Text, $Caption, $Button, $Icon)
    }
    catch
    {
      Write-Warning "Error occured: $_"
    }
  }
}

And here is how you’d use it:

 
PS> Show-MessageBox -Text 'Do you want to reboot now?' -Caption Reboot -Button YesNoCancel -Icon Exclamatio 
 

Twitter This Tip! ReTweet this Tip!

Anonymous
Parents
No Data
Comment
  • All I get is this:
    Unable to find type [Windows.MessageBoxButton].
    At line:15 char:4
    + [Windows.MessageBoxButton]
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (Windows.MessageBoxButton:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Children