POWERSHELL - Message Dialog Box Function

<#
.SYNOPSIS
    This script creates a function to display a message
    in a message block and then demonstrates this function.
.DESCRIPTION
    This script uses Windows Forms to generate a message
    box containing text and a window title passed as 
    parameters
.NOTES
    File Name  : Pop-Message.ps1
    Author     : Jeremy Thompson
    Requires   : PowerShell Version 3.0
.LINK
    This script posted to:
        http://sysadmeanderings.blogspot.com/
.EXAMPLE
     C:\> .\Pop-Message.ps1
#>

Function Pop-Message {

 [CmdletBinding()]
 Param ( 
    [Parameter(Mandatory=$True, 
      HelpMessage="Content of Message box")]
    [string]$Message ,

    [Parameter(Mandatory=$False,
     HelpMessage="Title for Message box")]
    [string]$BoxTitle = "Message"
 )          

 # in case, load the relevant assembly
 $v1 = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

 # use the messagebox class to display the message
 [Windows.Forms.MessageBox]::Show($Message, $BoxTitle, 
     [Windows.Forms.MessageBoxButtons]::OK , 
     [Windows.Forms.MessageBoxIcon]::Information) 

 } # End of Pop-Message function

# call Pop-Message function
Pop-Message 'Hello World!' 'IMA Message Box'

No comments:

Post a Comment