Functions/New-TextBlock.ps1

<#
.SYNOPSIS
    This function generates a block of text with options for indentation and newlines.
#>

function New-TextBlock {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([String])]
    param (
        # The script block which generates the content of the text block.
        [Parameter(Mandatory=$true, Position=0)]
        [ValidateNotNull()]
        [ScriptBlock]$content,

        # The number of spaces to add to the lines of the text block as indentation.
        [Parameter(Mandatory=$false)]
        [ValidateScript({ $_ -ge 0 })]
        [Int32]$indentationAmount = 4,

        # The number of newline characters to add to the end of the text block when it is returned.
        [Parameter(Mandatory=$false)]
        [ValidateNotNull()]
        [Int32]$appendNewLines = 0
    )
    # Call the script block to generate the text content
    # Combine using newlines to ensure that the text content is a single string
    $textBlock = (. $content) -join $CARRIAGE_RETURN_LINE_FEED

    # Split the text content into individual lines
    $textBlock = $textBlock.Split($LINE_FEED)

    # Add indentation to the lines and join back together into a single string
    $textBlock = ($textBlock | ForEach-Object -Process { (" " * $indentationAmount) + $_.Trim($CARRIAGE_RETURN) }) -join $CARRIAGE_RETURN_LINE_FEED

    # Append new lines if specified
    if ($appendNewLines -gt 0) {
        $textBlock += $CARRIAGE_RETURN_LINE_FEED * $appendNewLines
    }

    # Return the text block
    $textBlock
}