Public/Add-SpecSectionBreak.ps1

function Add-SpecSectionBreak {
    <#
    .SYNOPSIS
    This function adds a formatted section break with a customizable message to the console.
 
    .DESCRIPTION
    The Add-SpecSectionBreak function is used to display a formatted section break in the console with a specified message. The section break consists of a line of characters, a centered message, and another line of characters. The appearance of the section break can be customized by specifying the message, colour, character, length, and whether or not to add preceding asterisks.
 
    .PARAMETER Message
    The message to be displayed at the center of the section break.
 
    .PARAMETER Colour
    The colour of the characters in the section break line and message. Default is Cyan.
 
    .PARAMETER Character
    The character to be used for creating the section break line. Default is '-'.
 
    .PARAMETER Length
    The total length of the section break line. Default is 98.
 
    .PARAMETER DoNotAddPrecedingAsterisk
    A switch parameter that, when present, removes the preceding asterisk on each line of the section break.
 
    .EXAMPLE
    Add-SpecSectionBreak -Message "Section Break" -Colour "Blue" -Character "*" -Length 80
 
    This example adds a section break with the message "Section Break" using blue color, asterisk characters, and a line length of 80.
 
    .EXAMPLE
    Add-SpecSectionBreak -Message "Important Note" -Colour "Yellow" -Character "=" -Length 60
 
    This example adds a section break with the message "Important Note" using yellow color, equal sign characters, and a line length of 60.
 
    .EXAMPLE
    Add-SpecSectionBreak -Message "Error Details" -Colour "Red" -Character "#" -Length 50 -DoNotAddPrecedingAsterisk
 
    This example adds a section break with the message "Error Details" using red color, hash characters, a line length of 50, and omits the preceding asterisks.
 
    .EXAMPLE
    Add-SpecSectionBreak -Message "Custom Break" -Colour "Green" -Character "*" -Length 70
 
    This example adds a section break with the message "Custom Break" using green color, asterisk characters, and a line length of 70.
 
    .NOTES
    Author: andy.naftel
    Version: 1.0 - original code
             1.1 - [owen.heaume]
                       - Added comment-based help
                       - Added ValidateSet
                       - Added new switch
                       - Added default parameter values
    #>

    param (
        [Parameter(Mandatory = $true)]
        [string]$Message,

        [Parameter(Mandatory = $false)]
        [validateSet ("Black", "Blue", "Cyan", "DarkBlue", "DarkCyan", "DarkGray", "DarkMagenta", "DarkRed", "DarkYellow", "Gray", "Green", "Magenta", "Red", "White", "Yellow")]
        [string]$colour = 'Cyan',

        [Parameter(Mandatory = $false)]
        [char]$character = '-',

        [Parameter(Mandatory = $false)]
        [int]$Length = 98,

        [switch]
        $DoNotAddPrecedingAsterisk
    )

    $line = "$character" * $Length
    $Difference = "$character" * (($Length - $Message.length) / 2 - 2)
    $FullMessage = $Difference + " " + $Message + " " + $Difference

    Write-Host
    if ($DoNotAddPrecedingAsterisk.IsPresent) {
        Write-Host "$line" -ForegroundColor $colour
        Write-Host "$FullMessage" -ForegroundColor $colour
        Write-Host "$line" -ForegroundColor $colour
    } else {
        Write-Host "* $line" -ForegroundColor $colour
        Write-Host "* $FullMessage" -ForegroundColor $colour
        Write-Host "* $line" -ForegroundColor $colour
    }
    Write-Host
}