Skip to content

Commit 8bfec50

Browse files
temporary logging added
1 parent f42343e commit 8bfec50

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ function Get-CIPPTenantAlignment {
115115
}
116116

117117
# Check if template has tenant assignments (scope)
118-
$TemplateAssignedTenants = @()
118+
$TemplateAssignedTenants = Measure-CippTask -TaskName 'ResolveTenantScope' -EventName 'CIPP.AlignmentStatus' -Metadata @{
119+
Tenant = $TenantFilter
120+
TemplateGUID = $Template.GUID
121+
TemplateName = $Template.templateName
122+
} -Script {
123+
$Tenants = @()
119124
$AppliestoAllTenants = $false
120125

121126
if ($Template.tenantFilter -and $Template.tenantFilter.Count -gt 0) {
@@ -131,13 +136,25 @@ function Get-CIPPTenantAlignment {
131136
if ($TenantValues -contains 'AllTenants') {
132137
$AppliestoAllTenants = $true
133138
} else {
134-
$TemplateAssignedTenants = $TenantValues
139+
$Tenants = $TenantValues
135140
}
136141
} else {
137142
$AppliestoAllTenants = $true
138143
}
139-
140-
$StandardsData = foreach ($StandardKey in $TemplateStandards.PSObject.Properties.Name) {
144+
return @{
145+
Tenants = $Tenants
146+
AppliestoAllTenants = $AppliestoAllTenants
147+
}
148+
}
149+
$AppliestoAllTenants = $TemplateAssignedTenants.AppliestoAllTenants
150+
$TemplateAssignedTenants = $TemplateAssignedTenants.Tenants
151+
152+
$StandardsData = Measure-CippTask -TaskName 'BuildStandardsData' -EventName 'CIPP.AlignmentStatus' -Metadata @{
153+
Tenant = $TenantFilter
154+
TemplateGUID = $Template.GUID
155+
TemplateName = $Template.templateName
156+
} -Script {
157+
foreach ($StandardKey in $TemplateStandards.PSObject.Properties.Name) {
141158
$StandardConfig = $TemplateStandards.$StandardKey
142159
$StandardId = "standards.$StandardKey"
143160

@@ -207,9 +224,16 @@ function Get-CIPPTenantAlignment {
207224
}
208225
}
209226
}
227+
}
210228

211229
$AllStandards = $StandardsData.StandardId
212-
$ReportingEnabledStandards = ($StandardsData | Where-Object { $_.ReportingEnabled }).StandardId
230+
$ReportingEnabledStandards = Measure-CippTask -TaskName 'FilterStandardsLists' -EventName 'CIPP.AlignmentStatus' -Metadata @{
231+
Tenant = $TenantFilter
232+
TemplateGUID = $Template.GUID
233+
TemplateName = $Template.templateName
234+
} -Script {
235+
($StandardsData | Where-Object { $_.ReportingEnabled }).StandardId
236+
}
213237
$ReportingDisabledStandards = ($StandardsData | Where-Object { -not $_.ReportingEnabled }).StandardId
214238

215239
foreach ($TenantName in $TenantStandards.Keys) {
@@ -220,7 +244,12 @@ function Get-CIPPTenantAlignment {
220244
$AllCount = $AllStandards.Count
221245
$LatestDataCollection = $null
222246

223-
$ComparisonTable = foreach ($StandardKey in $AllStandards) {
247+
$ComparisonTable = Measure-CippTask -TaskName 'BuildComparisonTable' -EventName 'CIPP.AlignmentStatus' -Metadata @{
248+
Tenant = $TenantName
249+
TemplateGUID = $Template.GUID
250+
TemplateName = $Template.templateName
251+
} -Script {
252+
foreach ($StandardKey in $AllStandards) {
224253
$IsReportingDisabled = $ReportingDisabledStandards -contains $StandardKey
225254

226255
if ($TenantStandards[$TenantName].ContainsKey($StandardKey)) {
@@ -270,9 +299,15 @@ function Get-CIPPTenantAlignment {
270299
}
271300
}
272301
}
302+
}
273303

274-
$CompliantStandards = ($ComparisonTable | Where-Object { $_.ComplianceStatus -eq 'Compliant' }).Count
275-
$NonCompliantStandards = ($ComparisonTable | Where-Object { $_.ComplianceStatus -eq 'Non-Compliant' }).Count
304+
$CompliantStandards = Measure-CippTask -TaskName 'CalculateMetrics' -EventName 'CIPP.AlignmentStatus' -Metadata @{
305+
Tenant = $TenantName
306+
TemplateGUID = $Template.GUID
307+
TemplateName = $Template.templateName
308+
} -Script {
309+
($ComparisonTable | Where-Object { $_.ComplianceStatus -eq 'Compliant' }).Count
310+
}).Count
276311
$LicenseMissingStandards = ($ComparisonTable | Where-Object { $_.ComplianceStatus -eq 'License Missing' }).Count
277312
$ReportingDisabledStandardsCount = ($ComparisonTable | Where-Object { $_.ReportingDisabled }).Count
278313

@@ -288,7 +323,12 @@ function Get-CIPPTenantAlignment {
288323
0
289324
}
290325

291-
$Result = [PSCustomObject]@{
326+
$Result = Measure-CippTask -TaskName 'BuildResultObject' -EventName 'CIPP.AlignmentStatus' -Metadata @{
327+
Tenant = $TenantName
328+
TemplateGUID = $Template.GUID
329+
TemplateName = $Template.templateName
330+
} -Script {
331+
[PSCustomObject]@{
292332
TenantFilter = $TenantName
293333
StandardName = $Template.templateName
294334
StandardId = $Template.GUID
@@ -307,6 +347,7 @@ function Get-CIPPTenantAlignment {
307347
LatestDataCollection = if ($LatestDataCollection) { $LatestDataCollection } else { $null }
308348
ComparisonDetails = $ComparisonTable
309349
}
350+
}
310351

311352
$Results.Add($Result)
312353
}

0 commit comments

Comments
 (0)