Private/Export/Export-DetailsCsv.ps1

function Export-DetailsCsv {
    <#
    .SYNOPSIS
    Exports the detailed comparison results to CSV file.
     
    .DESCRIPTION
    Exports detailed policy-level differences to a CSV file named
    Baseline_Compare_Details.csv.
     
    Includes all Missing, Extra, and VersionMismatch policies with their
    assignment context and difference type.
     
    .PARAMETER Details
    Array of detail objects (combined Missing, Extra, VersionDiffs).
     
    .PARAMETER OutputPath
    Full path to the output CSV file.
     
    .EXAMPLE
    Export-DetailsCsv -Details $details -OutputPath "C:\Reports\Baseline_Compare_Details.csv"
     
    Exports details to specified CSV file.
     
    .OUTPUTS
    None. Writes CSV file to disk.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [object[]]$Details,
        
        [Parameter(Mandatory)]
        [string]$OutputPath
    )
    
    try {
        $Details | Sort-Object AssignmentDisplayName, DifferenceType, PolicyDisplayName | 
            Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
        
        Write-Host (" ✅ Details exported: {0}" -f (Split-Path $OutputPath -Leaf)) -ForegroundColor Green
    }
    catch {
        Write-Warning "Failed to export details CSV: $($_.Exception.Message)"
    }
}