Summary
Export-AzRetirementReport uses $allRecs += $Recommendations (array concatenation) in its process block, which creates a new array on every pipeline input. It then creates additional full copies for transformation and CSV sanitization.
Impact
For large recommendation sets, this causes O(n²) memory allocation from += and multiple full-set copies during export.
Location
Public/Export-AzRetirementReport.ps1
+= accumulation: line 39
- Transformation copy: lines 53–81
- CSV sanitization copy: lines 86–107
Suggested fix
Use [System.Collections.Generic.List[object]] instead of +=:
begin {
$allRecs = [System.Collections.Generic.List[object]]::new()
}
process {
foreach ($rec in $Recommendations) {
$allRecs.Add($rec)
}
}
For the transform and sanitize steps, consider processing items inline per format rather than creating separate full copies of the dataset.
Summary
Export-AzRetirementReportuses$allRecs += $Recommendations(array concatenation) in itsprocessblock, which creates a new array on every pipeline input. It then creates additional full copies for transformation and CSV sanitization.Impact
For large recommendation sets, this causes O(n²) memory allocation from
+=and multiple full-set copies during export.Location
Public/Export-AzRetirementReport.ps1+=accumulation: line 39Suggested fix
Use
[System.Collections.Generic.List[object]]instead of+=:For the transform and sanitize steps, consider processing items inline per format rather than creating separate full copies of the dataset.