Public/Export-VMPerformanceData.ps1

function Export-VMPerformanceData {
    <#
    .SYNOPSIS
        Writes VMPerformance rows to a CSV/Parquet file (plus manifest) on disk.

    .DESCRIPTION
        Thin public wrapper over the Write-MetricOutput writer. Use it to persist rows
        produced by Get-AzVMUtilization or Invoke-VMMetricsCollection.

    .PARAMETER Row
        The VMPerformance rows to write (pipeline-friendly).

    .PARAMETER Path
        Output file path.

    .PARAMETER Format
        'CSV' (default) or 'Parquet'.

    .PARAMETER Manifest
        Optional run metadata embedded in the sidecar manifest.

    .OUTPUTS
        [string] path of the data file written.
    #>

    # No SupportsShouldProcess here: the actual write/ShouldProcess happens in
    # Write-MetricOutput, and -WhatIf propagates to it via WhatIfPreference.
    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory, ValueFromPipeline)] [object[]] $Row,
        [Parameter(Mandatory)] [string] $Path,
        [ValidateSet('CSV', 'Parquet')] [string] $Format = 'CSV',
        [hashtable] $Manifest = @{}
    )

    begin { $all = [System.Collections.Generic.List[object]]::new() }
    process { foreach ($r in $Row) { $all.Add($r) } }
    end {
        Write-MetricOutput -Row $all.ToArray() -Path $Path -Format $Format -Manifest $Manifest
    }
}