Public/Set-specStatusMessage.ps1
Function Set-specStatusMessage { <# .SYNOPSIS Sets and displays status messages with customisable colours. .DESCRIPTION The `Set-specStatusMessage` function outputs messages to the host with specific colours based on the status provided. It supports different statuses such as Title, Info, Warning, Error, and Success. Additionally, it has an option to use a muted colour pallete for each status type. .PARAMETER Message Specifies the message(s) to be displayed. This parameter is mandatory and accepts an array of strings. .PARAMETER Status Specifies the status of the message. Valid values are 'Title', 'Info', 'Warning', 'Error', and 'Success'. The default value is 'Info'. .PARAMETER MuteColour A switch parameter that, when used, uses a muted colour pallete of the message based on the status type. .EXAMPLE Set-specStatusMessage -Message "This is an informational message." -Type Info Uses the default bright colour pallete. .EXAMPLE Set-specStatusMessage -Message "This is a warning message." -Type Warning -MuteColour Uses a muted version of the colour pallete. .EXAMPLE $x = @( [pscustomobject]@{ message = "Message1" type = "info" }, [pscustomobject]@{ message = "Message2" type = "error" } Uses an array of custom objects to display messages with different statuses. ) $x | Set-specStatusMessage -MuteColour .NOTES Author: owen.heaume Version: - 1.0 Initial release #> [cmdletBinding()] param ( [parameter (Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string[]]$Message, [parameter (Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [validateSet('Title', 'Info', 'Warning', 'Error', 'Success', 'Highlight')] [string]$Type = 'Info', [Switch]$MuteColour ) Begin {} Process { foreach ($msg in $Message) { switch ($Type) { 'Title' { if ($MuteColour) { Write-Host $msg -ForegroundColor DarkCyan } else { Write-Host $msg -ForegroundColor Cyan } } 'Info' { if ($MuteColour) { Write-Host $msg -ForegroundColor DarkGray } else { Write-Host $msg -ForegroundColor White } } 'Warning' { if ($MuteColour) { Write-Host $msg -ForegroundColor DarkYellow } else { Write-Host $msg -ForegroundColor Yellow } } 'Error' { Write-Host $msg -ForegroundColor Red } 'Success' { if ($MuteColour) { Write-Host $msg -ForegroundColor DarkGreen } else { Write-Host $msg -ForegroundColor Green } } 'Highlight' { if ($MuteColour) { Write-Host $msg -ForegroundColor DarkMagenta } else { Write-Host $msg -ForegroundColor Magenta } } } } } End { } } # Define an alias for the function Set-Alias -Name Status -Value Set-specStatusMessage |