Private/Convert-MatchCasing.ps1

function Convert-MatchCasing {
    <#
    .SYNOPSIS
        Adapts a replacement value to match the casing style of the text it replaces.
    .DESCRIPTION
        Internal helper. Given the actual matched text and a replacement value, returns the
        replacement re-cased to mirror the match: ALL CAPS, all lower, or PascalCase/Titlecase
        (first character upper). Any other style returns the replacement unchanged.
    #>

    param(
        [string]$Match,
        [string]$Replacement
    )

    if ($Match -ceq $Match.ToUpper()) {
        # ALL CAPS
        return $Replacement.ToUpper()
    } elseif ($Match -ceq $Match.ToLower()) {
        # all lower
        return $Replacement.ToLower()
    } elseif ($Match.Length -gt 0 -and [char]::IsUpper($Match[0])) {
        # PascalCase / Titlecase - uppercase first char
        return $Replacement.Substring(0, 1).ToUpper() + $Replacement.Substring(1)
    } else {
        return $Replacement
    }
}