Public/New-WFMessageBox.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function New-WFMessageBox
{
<#
    .SYNOPSIS
        The New-WFMessageBox functio will show a message box to the user
     
    .DESCRIPTION
        The New-WFMessageBox functio will show a message box to the user
     
    .PARAMETER Message
        Specifies the message to show
     
    .PARAMETER Title
        Specifies the title of the message box
     
    .PARAMETER Buttons
        Specifies which button to add. Just press tab to see the choices
     
    .PARAMETER Icon
        Specifies the icon to show. Just press tab to see the choices
     
    .EXAMPLE
        PS C:\> New-WFMessageBox -Message "Hello World" -Title "First Message" -Buttons "RetryCancel" -Icon "Asterix"
     
    .NOTES
        Author: Francois-Xavier Cat
        Twitter:@LazyWinAdm
        www.lazywinadmin.com
        github.com/lazywinadmin
#>

    
    [CmdletBinding(SupportsShouldProcess = $true)]
    [OutputType([System.Windows.Forms.DialogResult])]
    param
    (
        [Parameter(Mandatory = $true)]
        [String]$Message,
        
        [String]$Title,
        
        [System.Windows.Forms.MessageBoxButtons]$Buttons = "OK",
        
        [System.Windows.Forms.MessageBoxIcon]$Icon = "None"
    )
    
    BEGIN
    {
        Add-Type -AssemblyName System.Windows.Forms
    }
    PROCESS
    {
        if ($PSCmdlet.ShouldProcess("MessageBox", "Show a new message box"))
        {
            [System.Windows.Forms.MessageBox]::Show($Message, $Title, $Buttons, $Icon)
        }
    }
} #New-MessageBox