MessageFunctions.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
function Format-HostInformationMessage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [System.Object]$MessageData,
        [Alias("fg")]
        [System.ConsoleColor]$ForegroundColor = $Host.UI.RawUI.ForegroundColor,
        [Alias("bg")]
        [System.ConsoleColor]$BackgroundColor = $Host.UI.RawUI.BackgroundColor,
        [Switch]$NoNewline
    )
    [System.Management.Automation.HostInformationMessage]@{
        Message         = $MessageData
        ForegroundColor = $ForegroundColor
        BackgroundColor = $BackgroundColor
        NoNewline       = $NoNewline.IsPresent
    }
}

function Format-InformationMessage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [System.Object]$MessageData
    )
    Format-HostInformationMessage -MessageData "INFO: $MessageData"
}

function Format-WarningMessage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [System.Object]$MessageData
    )
    Format-HostInformationMessage -MessageData "WARNING: $MessageData" -ForegroundColor Yellow
}

function Format-ErrorMessage {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [System.Object]$MessageData
    )
    Format-HostInformationMessage -MessageData "ERROR: $MessageData" -ForegroundColor Red
}