This has been done by many other authors in various forms and using different methods.  This is just one more alternative…

function Show-MessageBox {
  PARAM (
    [parameter(Mandatory=$True, Position=0)] [string] $Caption,
    [parameter(Mandatory=$True, Position=1)] [string] $Message,
    [parameter(Mandatory=$False, Position=2)] 
      [ValidateSet("OkOnly","OkCancel","AbortRetryIgnore","YesNo","YesNoCancel","RetryCancel")] 
      [string] $ButtonSet = "OkOnly",
    [parameter(Mandatory=$False, Position=3)]
      [ValidateSet("None","Information","Question","Exclamation")]
      [string] $IconType = "None"
  )
  switch ($ButtonSet) {
    'RetryCancel' {$buttons = 5; break}
    'YesNo' {$buttons = 4; break}
    'YesNoCancel' {$buttons = 3; break}
    'AbortRetryIgnore' {$buttons = 2; break}
    'OkCancel' {$buttons = 1; break}
    default {$buttons = 0}
  }
  switch ($IconType) {
    'Information' {$icon = 64; break}
    'Exclamation' {$icon = 48; break}
    'Question' {$icon = 32; break}
    'Critical' {$icon = 16; break}
    default {$icon = 0}
  }
  $result = [System.Windows.Forms.MessageBox]::Show($Message, $Caption, $buttons, $icon) 
  return $result
}

$x = Show-MessageBox -Caption "Testing" -Message "Do you want to continue?" -ButtonSet YesNo -IconType Question
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s