Functions/Write-OutputMessage.ps1

<#
.SYNOPSIS
    This function writes a message to an output stream and returns it with a number of newlines appended.
#>

function Write-OutputMessage {
    [CmdletBinding(PositionalBinding=$true, DefaultParameterSetName="Information")]
    [OutputType([String])]
    param (
        # The message to write to output.
        [Parameter(Mandatory=$true, ParameterSetName="Information", Position=0)]
        [Parameter(Mandatory=$true, ParameterSetName="Warning", Position=0)]
        [Parameter(Mandatory=$true, ParameterSetName="Error", Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]$message,

        # The number of newlines to add to the end of the message when it is returned.
        [Parameter(Mandatory=$false, Position=1)]
        [ValidateNotNull()]
        [Int32]$appendNewLines,

        # Indicate that the message should be written to the information stream.
        [Parameter(Mandatory=$true, ParameterSetName="Information")]
        [Switch]$toInformation,

        # Indicate that the message should be written to the warning stream.
        [Parameter(Mandatory=$true, ParameterSetName="Warning")]
        [Switch]$toWarning,

        # Indicate that the message should be written to the error stream.
        [Parameter(Mandatory=$true, ParameterSetName="Error")]
        [Switch]$toError
    )

    # Write the message to output
    switch ($PSCmdlet.ParameterSetName) {
        Information {
            Write-Information $message
        }
        Warning {
            Write-Warning $message
        }
        Error {
            Write-Error $message
        }
    }

    # Return the message with new lines added
    $stringToAppend = ""
    if ($appendNewLines -gt 0) {
        $stringToAppend = "`r`n" * $appendNewLines
    }
    return ($message + $stringToAppend)
}