Public/Write-specAlignedStrings.ps1

function Write-specAlignedStrings {
    <#
    .SYNOPSIS
    Writes aligned label-value pairs to the console with specific colors.
 
    .DESCRIPTION
    This function writes multiple label-value pairs to the console, aligning the labels by their length.
    It supports up to five pairs, with the first two being mandatory and the rest optional.
    The labels and values are displayed with specified colors.
 
    .PARAMETER String1
    The first label to be displayed.
 
    .PARAMETER String1Value
    The value corresponding to the first label.
 
    .PARAMETER String2
    The second label to be displayed.
 
    .PARAMETER String2Value
    The value corresponding to the second label.
 
    .PARAMETER String3
    The third label to be displayed (optional).
 
    .PARAMETER String3Value
    The value corresponding to the third label (optional).
 
    .PARAMETER String4
    The fourth label to be displayed (optional).
 
    .PARAMETER String4Value
    The value corresponding to the fourth label (optional).
 
    .PARAMETER String5
    The fifth label to be displayed (optional).
 
    .PARAMETER String5Value
    The value corresponding to the fifth label (optional).
 
    .PARAMETER LabelColor
    The color of the label text. Defaults to 'DarkCyan'.
 
    .PARAMETER ValueColor
    The color of the value text. Defaults to 'DarkGray'.
 
    .EXAMPLE
    Write-specAlignedStrings -String1 'First Name' -String1Value 'John' -String2 'Last Name' -String2Value 'Doe' -String3 'Age' -String3Value '30'
 
    .EXAMPLE
    Write-specAlignedStrings -String1 'City' -String1Value 'London' -String2 'Country' -String2Value 'UK' -LabelColor 'Yellow' -ValueColor 'Magenta'
 
    .NOTES
    Author: owen.heaume
    Version: 1.0.0 - Initial release
    #>

    param (
        [Parameter()]
        [string]$String1,
        [Parameter()]
        [string]$String1Value,
        [Parameter()]
        [string]$String2,
        [Parameter()]
        [string]$String2Value,
        [string]$String3 = $null, # Optional
        [string]$String3Value = $null, # Optional
        [string]$String4 = $null, # Optional
        [string]$String4Value = $null, # Optional
        [string]$String5 = $null, # Optional
        [string]$String5Value = $null, # Optional
        [string]$LabelColor = 'DarkCyan',
        [string]$ValueColor = 'DarkGray'
    )

    # Calculate the maximum length across all provided strings
    $maxLabelLength = @($String1.Length, $String2.Length, $String3.Length, $String4.Length, $String5.Length | Where-Object { $_ -ne $null }) |
        Measure-Object -Maximum |
        Select-Object -ExpandProperty Maximum

    # Output all provided pairs
    Write-SinglePair -Label $String1 -Value $String1Value -LabelColor $LabelColor -ValueColor $ValueColor -MaxLabelLength $maxLabelLength
    Write-SinglePair -Label $String2 -Value $String2Value -LabelColor $LabelColor -ValueColor $ValueColor -MaxLabelLength $maxLabelLength
    if ($String3 -and $String3Value) {
        Write-SinglePair -Label $String3 -Value $String3Value -LabelColor $LabelColor -ValueColor $ValueColor -MaxLabelLength $maxLabelLength
    }
    if ($String4 -and $String4Value) {
        Write-SinglePair -Label $String4 -Value $String4Value -LabelColor $LabelColor -ValueColor $ValueColor -MaxLabelLength $maxLabelLength
    }
    if ($String5 -and $String5Value) {
        Write-SinglePair -Label $String5 -Value $String5Value -LabelColor $LabelColor -ValueColor $ValueColor -MaxLabelLength $maxLabelLength
    }
}