Skip to content

Commit 5702b8d

Browse files
fix write hosts
1 parent fe773be commit 5702b8d

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListTenantAlignment.ps1

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ function Invoke-ListTenantAlignment {
8989
Write-Host "Template '$($Template.templateName)' applies to all tenants (no tenantFilter)"
9090
}
9191

92-
# Track all standards and their reporting status like the frontend does
9392
$AllStandards = [System.Collections.Generic.List[string]]::new()
9493
$ReportingEnabledStandards = [System.Collections.Generic.List[string]]::new()
9594
$ReportingDisabledStandards = [System.Collections.Generic.List[string]]::new()
@@ -98,8 +97,7 @@ function Invoke-ListTenantAlignment {
9897
$StandardConfig = $TemplateStandards.$StandardKey
9998
$StandardId = "standards.$StandardKey"
10099

101-
# Check if reporting is enabled for this standard (same logic as frontend)
102-
# Try multiple possible action property locations
100+
103101
$Actions = @()
104102
if ($StandardConfig.action) {
105103
$Actions = $StandardConfig.action
@@ -109,13 +107,11 @@ function Invoke-ListTenantAlignment {
109107
$Actions = $StandardConfig.PSObject.Properties['action'].Value
110108
}
111109

112-
# Frontend logic: actions.filter(action => action?.value.toLowerCase() === "report" || action?.value.toLowerCase() === "remediate").length > 0
113110
$ReportingEnabled = $false
114111
if ($Actions -and $Actions.Count -gt 0) {
115112
$ReportingEnabled = ($Actions | Where-Object { $_.value -and ($_.value.ToLower() -eq 'report' -or $_.value.ToLower() -eq 'remediate') }).Count -gt 0
116113
}
117114

118-
# Add to all standards list
119115
$AllStandards.Add($StandardId)
120116

121117
if ($ReportingEnabled) {
@@ -124,9 +120,7 @@ function Invoke-ListTenantAlignment {
124120
$ReportingDisabledStandards.Add($StandardId)
125121
}
126122

127-
# Handle IntuneTemplate arrays - don't count the base IntuneTemplate, only the specific instances
128123
if ($StandardKey -eq 'IntuneTemplate' -and $StandardConfig -is [array]) {
129-
# Remove the base IntuneTemplate standard since we'll add specific instances
130124
$AllStandards.Remove($StandardId)
131125
if ($ReportingEnabled) {
132126
$ReportingEnabledStandards.Remove($StandardId)
@@ -138,44 +132,32 @@ function Invoke-ListTenantAlignment {
138132
if ($IntuneTemplate.TemplateList.value) {
139133
$IntuneStandardId = "standards.IntuneTemplate.$($IntuneTemplate.TemplateList.value)"
140134

141-
# Check if reporting is enabled for this Intune template
142135
$IntuneActions = if ($IntuneTemplate.action) { $IntuneTemplate.action } else { @() }
143-
Write-Host " Intune template $IntuneStandardId actions: $($IntuneActions | ForEach-Object { $_.value } | Join-String -Separator ', ')"
144136
$IntuneReportingEnabled = ($IntuneActions | Where-Object { $_.value -and ($_.value.ToLower() -eq 'report' -or $_.value.ToLower() -eq 'remediate') }).Count -gt 0
145-
Write-Host " Intune template $IntuneStandardId reporting enabled: $IntuneReportingEnabled"
146137

147-
# Add to all standards list
148138
$AllStandards.Add($IntuneStandardId)
149139

150140
if ($IntuneReportingEnabled) {
151141
$ReportingEnabledStandards.Add($IntuneStandardId)
152-
Write-Host " Added $IntuneStandardId to reporting enabled"
153142
} else {
154143
$ReportingDisabledStandards.Add($IntuneStandardId)
155-
Write-Host " Added $IntuneStandardId to reporting disabled"
156144
}
157145
}
158146
}
159147
}
160148
}
161149

162-
# Process each tenant against this template (but only if template applies to this tenant)
163150
foreach ($TenantName in $TenantStandards.Keys) {
164-
# Skip this tenant if template is assigned to specific tenants and this tenant is not in the list
165151
if (-not $AppliestoAllTenants -and $TenantName -notin $TemplateAssignedTenants) {
166152
Write-Host "Skipping tenant '$TenantName' for template '$($Template.templateName)' - not in assigned tenant list"
167153
continue
168154
}
169155
$AllCount = $AllStandards.Count
170156

171-
# Check compliance for ALL standards (both reporting enabled and disabled)
172-
# But track them separately like the frontend does
173157
$CompliantStandards = 0
174158
$NonCompliantStandards = 0
175159
$ReportingDisabledStandardsCount = 0
176160
$LatestDataCollection = $null
177-
178-
# Create a table to compare with frontend
179161
$ComparisonTable = @()
180162

181163
foreach ($StandardKey in $AllStandards) {
@@ -185,18 +167,15 @@ function Invoke-ListTenantAlignment {
185167
$StandardObject = $TenantStandards[$TenantName][$StandardKey]
186168
$Value = $StandardObject.Value
187169

188-
# Track the latest data collection timestamp
189170
if ($StandardObject.LastRefresh) {
190171
$RefreshTime = [DateTime]::Parse($StandardObject.LastRefresh)
191172
if (-not $LatestDataCollection -or $RefreshTime -gt $LatestDataCollection) {
192173
$LatestDataCollection = $RefreshTime
193174
}
194175
}
195176

196-
# Use strict compliance logic - only explicit TRUE is compliant
197177
$IsCompliant = ($Value -eq $true)
198178

199-
# Count based on reporting status like the frontend
200179
if ($IsReportingDisabled) {
201180
$ReportingDisabledStandardsCount++
202181
$ComplianceStatus = 'Reporting Disabled'
@@ -216,7 +195,6 @@ function Invoke-ListTenantAlignment {
216195
ReportingDisabled = $IsReportingDisabled
217196
}
218197
} else {
219-
# If standard not found, count as non-compliant if reporting enabled, or reporting disabled if reporting disabled
220198
if ($IsReportingDisabled) {
221199
$ReportingDisabledStandardsCount++
222200
$ComplianceStatus = 'Reporting Disabled'
@@ -235,26 +213,14 @@ function Invoke-ListTenantAlignment {
235213
}
236214
}
237215

238-
# Calculate percentage using the exact same formula as the frontend
239-
# Frontend: Math.round((compliantCount / (allCount - reportingDisabledCount || 1)) * 100)
216+
240217
$AlignmentPercentage = if (($AllCount - $ReportingDisabledStandardsCount) -gt 0) {
241218
[Math]::Round(($CompliantStandards / ($AllCount - $ReportingDisabledStandardsCount)) * 100)
242219
} else {
243220
0
244221
}
245222

246-
# Output comparison table for debugging
247-
Write-Host "=== TENANT: $TenantName | TEMPLATE: $($Template.templateName) ==="
248-
Write-Host "TEMPLATE STANDARDS FOUND: $($AllStandards -join ', ')"
249-
Write-Host "TENANT STANDARDS AVAILABLE: $($TenantStandards[$TenantName].Keys | Sort-Object | Join-String -Separator ', ')"
250-
251-
# Check for tenant standards that might be missing from template
252223
$TenantOnlyStandards = $TenantStandards[$TenantName].Keys | Where-Object { $_ -notin $AllStandards }
253-
Write-Host "TENANT-ONLY STANDARDS (not in template): $($TenantOnlyStandards -join ', ')"
254-
255-
Write-Host "CALCULATION: $CompliantStandards compliant / ($AllCount total - $ReportingDisabledStandardsCount reporting disabled) = $AlignmentPercentage%"
256-
Write-Host ''
257-
Write-Host ($ComparisonTable | Format-Table -Property StandardName, Compliant, ComplianceStatus, ReportingDisabled, StandardValue -AutoSize | Out-String)
258224

259225
$Result = [PSCustomObject]@{
260226
tenantFilter = $TenantName

0 commit comments

Comments
 (0)