Skip to content

Commit 6cab31a

Browse files
drift profiling
1 parent 5ba5355 commit 6cab31a

File tree

2 files changed

+2
-74
lines changed

2 files changed

+2
-74
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Get-CIPPTenantAlignment {
3333
$sw = [System.Diagnostics.Stopwatch]::StartNew()
3434
$TemplateTable = Get-CippTable -tablename 'templates'
3535
$TemplateFilter = "PartitionKey eq 'StandardsTemplateV2'"
36+
$TenantGroups = Get-TenantGroups
3637
$sw.Stop()
3738
$SectionTimings['TemplateTableInit'] = $sw.ElapsedMilliseconds
3839
Write-Verbose "Template table initialization took: $($sw.ElapsedMilliseconds)ms"
@@ -158,7 +159,7 @@ function Get-CIPPTenantAlignment {
158159
# Extract tenant values from the tenantFilter array
159160
$TenantValues = $Template.tenantFilter | ForEach-Object {
160161
if ($_.type -eq 'group') {
161-
(Get-TenantGroups -GroupId $_.value).members.defaultDomainName
162+
($TenantGroups | Where-Object -Property GroupName -EQ $_.value).Members.defaultDomainName
162163
} else {
163164
$_.value
164165
}

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,9 @@ function Get-CIPPDrift {
2929
[switch]$AllTenants
3030
)
3131

32-
# Initialize overall stopwatch
33-
$OverallStopwatch = [System.Diagnostics.Stopwatch]::StartNew()
34-
$SectionTimings = @{}
35-
36-
# Measure license capability checks
37-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
3832
$IntuneCapable = Test-CIPPStandardLicense -StandardName 'IntuneTemplate_general' -TenantFilter $TenantFilter -RequiredCapabilities @('INTUNE_A', 'MDM_Services', 'EMS', 'SCCM', 'MICROSOFTINTUNEPLAN1')
3933
$ConditionalAccessCapable = Test-CIPPStandardLicense -StandardName 'ConditionalAccessTemplate_general' -TenantFilter $TenantFilter -RequiredCapabilities @('AAD_PREMIUM', 'AAD_PREMIUM_P2')
4034
$IntuneTable = Get-CippTable -tablename 'templates'
41-
$sw.Stop()
42-
$SectionTimings['LicenseChecks'] = $sw.ElapsedMilliseconds
43-
Write-Verbose "License checks took: $($sw.ElapsedMilliseconds)ms"
44-
45-
# Measure Intune template loading
46-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
4735
if ($IntuneCapable) {
4836
$IntuneFilter = "PartitionKey eq 'IntuneTemplate'"
4937
$RawIntuneTemplates = (Get-CIPPAzDataTableEntity @IntuneTable -Filter $IntuneFilter)
@@ -61,12 +49,6 @@ function Get-CIPPDrift {
6149
}
6250
} | Sort-Object -Property displayName
6351
}
64-
$sw.Stop()
65-
$SectionTimings['IntuneTemplateLoading'] = $sw.ElapsedMilliseconds
66-
Write-Verbose "Intune template loading took: $($sw.ElapsedMilliseconds)ms"
67-
68-
# Measure CA template loading
69-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
7052
# Load all CA templates
7153
if ($ConditionalAccessCapable) {
7254
$CAFilter = "PartitionKey eq 'CATemplate'"
@@ -81,25 +63,15 @@ function Get-CIPPDrift {
8163
}
8264
} | Sort-Object -Property displayName
8365
}
84-
$sw.Stop()
85-
$SectionTimings['CATemplateLoading'] = $sw.ElapsedMilliseconds
86-
Write-Verbose "CA template loading took: $($sw.ElapsedMilliseconds)ms"
8766

8867
try {
89-
# Measure alignment data retrieval
90-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
9168
$AlignmentData = Get-CIPPTenantAlignment -TenantFilter $TenantFilter -TemplateId $TemplateId | Where-Object -Property standardType -EQ 'drift'
92-
$sw.Stop()
93-
$SectionTimings['AlignmentDataRetrieval'] = $sw.ElapsedMilliseconds
94-
Write-Verbose "Alignment data retrieval took: $($sw.ElapsedMilliseconds)ms"
9569

9670
if (-not $AlignmentData) {
9771
Write-Warning "No alignment data found for tenant $TenantFilter"
9872
return @()
9973
}
10074

101-
# Measure drift state loading
102-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
10375
# Get existing drift states from the tenantDrift table
10476
$DriftTable = Get-CippTable -tablename 'tenantDrift'
10577
$DriftFilter = "PartitionKey eq '$TenantFilter'"
@@ -112,14 +84,9 @@ function Get-CIPPDrift {
11284
} catch {
11385
Write-Warning "Failed to get existing drift states: $($_.Exception.Message)"
11486
}
115-
$sw.Stop()
116-
$SectionTimings['DriftStateLoading'] = $sw.ElapsedMilliseconds
117-
Write-Verbose "Drift state loading took: $($sw.ElapsedMilliseconds)ms"
11887

11988
$Results = [System.Collections.Generic.List[object]]::new()
12089
foreach ($Alignment in $AlignmentData) {
121-
# Measure standards deviation processing
122-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
12390
# Initialize deviation collections
12491
$StandardsDeviations = [System.Collections.Generic.List[object]]::new()
12592
$PolicyDeviations = [System.Collections.Generic.List[object]]::new()
@@ -172,12 +139,7 @@ function Get-CIPPDrift {
172139
}
173140
}
174141
}
175-
$sw.Stop()
176-
$SectionTimings['StandardsDeviationProcessing'] = $sw.ElapsedMilliseconds
177-
Write-Verbose "Standards deviation processing took: $($sw.ElapsedMilliseconds)ms"
178142

179-
# Measure Intune policy collection
180-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
181143
# Perform full policy collection
182144
if ($IntuneCapable) {
183145
# Always get live data when not in AllTenants mode
@@ -248,12 +210,6 @@ function Get-CIPPDrift {
248210
Write-Warning "Failed to get Intune policies: $($_.Exception.Message)"
249211
}
250212
}
251-
$sw.Stop()
252-
$SectionTimings['IntunePolicyCollection'] = $sw.ElapsedMilliseconds
253-
Write-Verbose "Intune policy collection took: $($sw.ElapsedMilliseconds)ms"
254-
255-
# Measure CA policy collection
256-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
257213
# Get Conditional Access policies
258214
if ($ConditionalAccessCapable) {
259215
try {
@@ -271,12 +227,7 @@ function Get-CIPPDrift {
271227
$TenantCAPolicies = @()
272228
}
273229
}
274-
$sw.Stop()
275-
$SectionTimings['CAPolicyCollection'] = $sw.ElapsedMilliseconds
276-
Write-Verbose "CA policy collection took: $($sw.ElapsedMilliseconds)ms"
277230

278-
# Measure template extraction
279-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
280231
if ($Alignment.standardSettings) {
281232
if ($Alignment.standardSettings.IntuneTemplate) {
282233
$IntuneTemplateIds = $Alignment.standardSettings.IntuneTemplate.TemplateList | ForEach-Object { $_.value }
@@ -304,12 +255,7 @@ function Get-CIPPDrift {
304255
Write-Warning "Failed to get Intune templates: $($_.Exception.Message)"
305256
}
306257
}
307-
$sw.Stop()
308-
$SectionTimings['TemplateExtraction'] = $sw.ElapsedMilliseconds
309-
Write-Verbose "Template extraction took: $($sw.ElapsedMilliseconds)ms"
310258

311-
# Measure Intune policy deviation checking
312-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
313259
# Check for extra Intune policies not in template
314260
foreach ($TenantPolicy in $TenantIntunePolicies) {
315261
$PolicyFound = $false
@@ -345,12 +291,7 @@ function Get-CIPPDrift {
345291
$PolicyDeviations.Add($PolicyDeviation)
346292
}
347293
}
348-
$sw.Stop()
349-
$SectionTimings['IntunePolicyDeviationCheck'] = $sw.ElapsedMilliseconds
350-
Write-Verbose "Intune policy deviation check took: $($sw.ElapsedMilliseconds)ms"
351294

352-
# Measure CA policy deviation checking
353-
$sw = [System.Diagnostics.Stopwatch]::StartNew()
354295
# Check for extra Conditional Access policies not in template
355296
foreach ($TenantCAPolicy in $TenantCAPolicies) {
356297
$PolicyFound = $false
@@ -380,9 +321,6 @@ function Get-CIPPDrift {
380321
$PolicyDeviations.Add($PolicyDeviation)
381322
}
382323
}
383-
$sw.Stop()
384-
$SectionTimings['CAPolicyDeviationCheck'] = $sw.ElapsedMilliseconds
385-
Write-Verbose "CA policy deviation check took: $($sw.ElapsedMilliseconds)ms"
386324

387325

388326
# Combine all deviations and filter by status
@@ -422,17 +360,6 @@ function Get-CIPPDrift {
422360
$Results.Add($Result)
423361
}
424362

425-
# Output timing summary
426-
$OverallStopwatch.Stop()
427-
Write-Information '=== Get-CIPPDrift Performance Summary ==='
428-
Write-Information "Total execution time: $($OverallStopwatch.ElapsedMilliseconds)ms"
429-
Write-Information "`nSection timings:"
430-
foreach ($Section in $SectionTimings.GetEnumerator() | Sort-Object Value -Descending) {
431-
$Percentage = [math]::Round(($Section.Value / $OverallStopwatch.ElapsedMilliseconds) * 100, 2)
432-
Write-Information " $($Section.Key): $($Section.Value)ms ($Percentage%)"
433-
}
434-
Write-Information "========================================`n"
435-
436363
return @($Results)
437364

438365
} catch {

0 commit comments

Comments
 (0)