@@ -215,7 +215,7 @@ securityresources
215215| order by recommendationDisplayName asc
216216'@
217217
218- # KQL 2: MCSB compliance assessments — full query (same as Test-Assessment.50002)
218+ # KQL 2: MCSB compliance assessments — full query
219219 # Returns all fields needed to emit standalone test results for MCSB-only recommendations.
220220 $mcsbQuery = @'
221221securityresources
@@ -453,10 +453,14 @@ $remediationSection
453453 $applicableRows = @ ($rows | Where-Object { $_.state -ne ' NotApplicable' })
454454 $notApplicableRows = @ ($rows | Where-Object { $_.state -eq ' NotApplicable' })
455455
456- # Column presence flags
457- $showResourceGroup = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceGroup ) } | Select-Object - First 1 )
458- $showResourceType = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceType ) } | Select-Object - First 1 )
459- $showResource = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceName ) } | Select-Object - First 1 )
456+ # Column presence flags — single pass, short-circuits once all three are found
457+ $showResourceGroup = $false ; $showResourceType = $false ; $showResource = $false
458+ foreach ($r in $rows ) {
459+ if (-not $showResourceGroup -and -not [string ]::IsNullOrWhiteSpace($r.resourceGroup )) { $showResourceGroup = $true }
460+ if (-not $showResourceType -and -not [string ]::IsNullOrWhiteSpace($r.resourceType )) { $showResourceType = $true }
461+ if (-not $showResource -and -not [string ]::IsNullOrWhiteSpace($r.resourceName )) { $showResource = $true }
462+ if ($showResourceGroup -and $showResourceType -and $showResource ) { break }
463+ }
460464
461465 # Dynamic table header
462466 $tableHeader = ' |'
@@ -606,10 +610,14 @@ $remediationSection
606610 $applicableRows = @ ($rows | Where-Object { $_.resourceState -ne ' notapplicable' })
607611 $notApplicableRows = @ ($rows | Where-Object { $_.resourceState -eq ' notapplicable' })
608612
609- # Column presence flags
610- $showResourceGroup = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceGroup ) } | Select-Object - First 1 )
611- $showResourceType = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceType ) } | Select-Object - First 1 )
612- $showResource = [bool ]($rows | Where-Object { -not [string ]::IsNullOrWhiteSpace($_.resourceName ) } | Select-Object - First 1 )
613+ # Column presence flags — single pass, short-circuits once all three are found
614+ $showResourceGroup = $false ; $showResourceType = $false ; $showResource = $false
615+ foreach ($r in $rows ) {
616+ if (-not $showResourceGroup -and -not [string ]::IsNullOrWhiteSpace($r.resourceGroup )) { $showResourceGroup = $true }
617+ if (-not $showResourceType -and -not [string ]::IsNullOrWhiteSpace($r.resourceType )) { $showResourceType = $true }
618+ if (-not $showResource -and -not [string ]::IsNullOrWhiteSpace($r.resourceName )) { $showResource = $true }
619+ if ($showResourceGroup -and $showResourceType -and $showResource ) { break }
620+ }
613621
614622 # Dynamic table header — MCSB control columns are always present for MCSB-only recs
615623 $tableHeader = ' |'
0 commit comments