Private/ConvertTo-FriendlySize.ps1

function ConvertTo-FriendlySize {
    <#
    .SYNOPSIS
        Converts a kilobyte value into a friendly GB/MB string.
 
    .DESCRIPTION
        Internal helper used by public functions to format raw KB
        values from CIM/WMI into human-readable sizes. Not exported.
 
    .PARAMETER KB
        The size in kilobytes to convert.
 
    .EXAMPLE
        ConvertTo-FriendlySize -KB 2097152
        # Returns "2 GB"
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [double]$KB
    )

    $bytes = $KB * 1KB

    if ($bytes -ge 1GB) {
        "{0} GB" -f [math]::Round($bytes / 1GB, 2)
    } else {
        "{0} MB" -f [math]::Round($bytes / 1MB, 2)
    }
}