@@ -236,69 +236,101 @@ function Get-CIPPTenantAlignment {
236236 StandardsCount = $AllStandards.Count
237237 AppliesToAll = $AppliestoAllTenants
238238 } - Script {
239- if (-not $AppliestoAllTenants -and $TenantName -notin $TemplateAssignedTenants ) {
240- return
239+ Measure-CippTask - TaskName ' Template.CheckTenantScope' - EventName ' CIPP.TenantAlignment.Profile' - Metadata @ {
240+ TenantName = $TenantName
241+ } - Script {
242+ if (-not $AppliestoAllTenants -and $TenantName -notin $TemplateAssignedTenants ) {
243+ return
244+ }
241245 }
242246
243247 $AllCount = $AllStandards.Count
244- $LatestDataCollection = $null
248+ $script : LatestDataCollection = $null
245249
246250 $ComparisonTable = Measure-CippTask - TaskName ' Template.BuildComparisonTable' - EventName ' CIPP.TenantAlignment.Profile' - Metadata @ {
247251 TemplateGUID = $Template.GUID
248252 TenantName = $TenantName
249253 StandardsCount = $AllStandards.Count
250254 } - Script {
251- foreach ($StandardKey in $AllStandards ) {
252- $IsReportingDisabled = $ReportingDisabledStandards -contains $StandardKey
253-
254- if ($TenantStandards [$TenantName ].ContainsKey($StandardKey )) {
255- $StandardObject = $TenantStandards [$TenantName ][$StandardKey ]
256- $Value = $StandardObject.Value
255+ $ComparisonResults = [System.Collections.Generic.List [object ]]::new()
256+
257+ Measure-CippTask - TaskName ' Template.IterateStandards' - EventName ' CIPP.TenantAlignment.Profile' - Metadata @ {
258+ StandardsCount = $AllStandards.Count
259+ } - Script {
260+ foreach ($StandardKey in $AllStandards ) {
261+ Measure-CippTask - TaskName ' Template.ProcessStandard' - EventName ' CIPP.TenantAlignment.Profile' - Metadata @ {
262+ StandardKey = $StandardKey
263+ } - Script {
264+ $IsReportingDisabled = Measure-CippTask - TaskName ' Template.CheckReportingDisabled' - EventName ' CIPP.TenantAlignment.Profile' - Script {
265+ $ReportingDisabledStandards -contains $StandardKey
266+ }
257267
258- if ($StandardObject.LastRefresh ) {
259- $RefreshTime = [DateTime ]::Parse($StandardObject.LastRefresh )
260- if (-not $LatestDataCollection -or $RefreshTime -gt $LatestDataCollection ) {
261- $LatestDataCollection = $RefreshTime
268+ $HasStandard = Measure-CippTask - TaskName ' Template.CheckHasStandard' - EventName ' CIPP.TenantAlignment.Profile' - Script {
269+ $TenantStandards [$TenantName ].ContainsKey($StandardKey )
262270 }
263- }
264271
265- $IsCompliant = ($Value -eq $true )
266- $IsCompliant = ($Value -eq $true )
267- $IsLicenseMissing = ($Value -is [string ] -and $Value -like ' License Missing:*' )
268-
269- if ($IsReportingDisabled ) {
270- $ComplianceStatus = ' Reporting Disabled'
271- } elseif ($IsCompliant ) {
272- $ComplianceStatus = ' Compliant'
273- } elseif ($IsLicenseMissing ) {
274- $ComplianceStatus = ' License Missing'
275- } else {
276- $ComplianceStatus = ' Non-Compliant'
277- }
272+ if ($HasStandard ) {
273+ $StandardObject = Measure-CippTask - TaskName ' Template.GetStandardObject' - EventName ' CIPP.TenantAlignment.Profile' - Script {
274+ $TenantStandards [$TenantName ][$StandardKey ]
275+ }
278276
279- [PSCustomObject ]@ {
280- StandardName = $StandardKey
281- Compliant = $IsCompliant
282- StandardValue = ($Value | ConvertTo-Json - Depth 100 - Compress)
283- ComplianceStatus = $ComplianceStatus
284- ReportingDisabled = $IsReportingDisabled
285- }
286- } else {
287- if ($IsReportingDisabled ) {
288- $ComplianceStatus = ' Reporting Disabled'
289- } else {
290- $ComplianceStatus = ' Non-Compliant'
291- }
277+ $Value = $StandardObject.Value
292278
293- [PSCustomObject ]@ {
294- StandardName = $StandardKey
295- Compliant = $false
296- StandardValue = ' NOT FOUND'
297- ComplianceStatus = $ComplianceStatus
298- ReportingDisabled = $IsReportingDisabled
279+ Measure-CippTask - TaskName ' Template.UpdateLatestRefresh' - EventName ' CIPP.TenantAlignment.Profile' - Script {
280+ if ($StandardObject.LastRefresh ) {
281+ $RefreshTime = [DateTime ]::Parse($StandardObject.LastRefresh )
282+ if (-not $script :LatestDataCollection -or $RefreshTime -gt $script :LatestDataCollection ) {
283+ $script :LatestDataCollection = $RefreshTime
284+ }
285+ }
286+ }
287+
288+ $IsCompliant = ($Value -eq $true )
289+ $IsLicenseMissing = ($Value -is [string ] -and $Value -like ' License Missing:*' )
290+
291+ $ComplianceStatus = Measure-CippTask - TaskName ' Template.DetermineStatus' - EventName ' CIPP.TenantAlignment.Profile' - Script {
292+ if ($IsReportingDisabled ) {
293+ ' Reporting Disabled'
294+ } elseif ($IsCompliant ) {
295+ ' Compliant'
296+ } elseif ($IsLicenseMissing ) {
297+ ' License Missing'
298+ } else {
299+ ' Non-Compliant'
300+ }
301+ }
302+
303+ $StandardValueJson = Measure-CippTask - TaskName ' Template.ConvertToJson' - EventName ' CIPP.TenantAlignment.Profile' - Script {
304+ $Value | ConvertTo-Json - Depth 5 - Compress
305+ }
306+
307+ $ComparisonResults.Add ([PSCustomObject ]@ {
308+ StandardName = $StandardKey
309+ Compliant = $IsCompliant
310+ StandardValue = $StandardValueJson
311+ ComplianceStatus = $ComplianceStatus
312+ ReportingDisabled = $IsReportingDisabled
313+ })
314+ } else {
315+ $ComplianceStatus = if ($IsReportingDisabled ) {
316+ ' Reporting Disabled'
317+ } else {
318+ ' Non-Compliant'
319+ }
320+
321+ $ComparisonResults.Add ([PSCustomObject ]@ {
322+ StandardName = $StandardKey
323+ Compliant = $false
324+ StandardValue = ' NOT FOUND'
325+ ComplianceStatus = $ComplianceStatus
326+ ReportingDisabled = $IsReportingDisabled
327+ })
328+ }
299329 }
300330 }
301331 }
332+
333+ $ComparisonResults
302334 }
303335
304336 Measure-CippTask - TaskName ' Template.CalculateScores' - EventName ' CIPP.TenantAlignment.Profile' - Metadata @ {
@@ -338,7 +370,7 @@ function Get-CIPPTenantAlignment {
338370 LicenseMissingStandards = $LicenseMissingStandards
339371 TotalStandards = $AllCount
340372 ReportingDisabledCount = $ReportingDisabledStandardsCount
341- LatestDataCollection = if ($LatestDataCollection ) { $LatestDataCollection } else { $null }
373+ LatestDataCollection = if ($script : LatestDataCollection ) { $script : LatestDataCollection } else { $null }
342374 ComparisonDetails = $ComparisonTable
343375 }
344376
0 commit comments