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
  • One could also just do this..

    'community.idera.com/powershell/powertips/b/tips/posts/displaying-message-boxes'

    Or just use this module

    Designed to facilitate script input/output with an easily customizable WPF window.

    'powershellgallery.com/packages/AnyBox/0.3.0'

    Authors site - instructions -

    'donaldmellenbruch.com/post/introducing-the-anybox'

Comment Children
No Data