Summary
In the Az.Advisor code path, ExtendedProperty JSON is parsed once during the Where-Object subcategory filter, then parsed again when building the output object for each matching recommendation.
Impact
Redundant ConvertFrom-Json calls add unnecessary CPU overhead, especially noticeable with large recommendation sets across many subscriptions.
Location
Public/Get-AzRetirementRecommendation.ps1
- First parse: subcategory filter scriptblock (~line 162)
- Second parse: output object construction (~line 234)
Suggested fix
Parse ExtendedProperty once during filtering and cache the result on the object:
$subcategoryFilter = {
if ($_.ExtendedProperty) {
$extProps = $_.ExtendedProperty | ConvertFrom-Json
if ($extProps.recommendationSubCategory -eq "ServiceUpgradeAndRetirement") {
$_ | Add-Member -NotePropertyName ExtendedPropertyObject -NotePropertyValue $extProps -Force
$true
} else { $false }
}
else { $false }
}
The downstream code already checks for ExtendedPropertyObject and reuses it — this change just moves the caching into the filter so every retained item benefits.
Summary
In the Az.Advisor code path,
ExtendedPropertyJSON is parsed once during theWhere-Objectsubcategory filter, then parsed again when building the output object for each matching recommendation.Impact
Redundant
ConvertFrom-Jsoncalls add unnecessary CPU overhead, especially noticeable with large recommendation sets across many subscriptions.Location
Public/Get-AzRetirementRecommendation.ps1Suggested fix
Parse
ExtendedPropertyonce during filtering and cache the result on the object:The downstream code already checks for
ExtendedPropertyObjectand reuses it — this change just moves the caching into the filter so every retained item benefits.