@@ -47,6 +47,19 @@ function Get-CIPPDrift {
4747 }
4848 } | Sort-Object - Property displayName
4949
50+ # Load all CA templates
51+ $CAFilter = " PartitionKey eq 'CATemplate'"
52+ $RawCATemplates = (Get-CIPPAzDataTableEntity @IntuneTable - Filter $CAFilter )
53+ $AllCATemplates = $RawCATemplates | ForEach-Object {
54+ try {
55+ $data = $_.JSON | ConvertFrom-Json - Depth 100 - ErrorAction SilentlyContinue
56+ $data | Add-Member - NotePropertyName ' GUID' - NotePropertyValue $_.RowKey - Force
57+ $data
58+ } catch {
59+ # Skip invalid templates
60+ }
61+ } | Sort-Object - Property displayName
62+
5063 try {
5164 $AlignmentData = Get-CIPPTenantAlignment - TenantFilter $TenantFilter - TemplateId $TemplateId | Where-Object - Property standardType -EQ ' drift'
5265 if (-not $AlignmentData ) {
@@ -82,18 +95,35 @@ function Get-CIPPDrift {
8295 } else {
8396 ' New'
8497 }
98+ # Reset displayName and description for each deviation to prevent carryover from previous iterations
99+ $displayName = $null
100+ $standardDescription = $null
85101 # if the $ComparisonItem.StandardName contains *intuneTemplate*, then it's an Intune policy deviation, and we need to grab the correct displayname from the template table
86102 if ($ComparisonItem.StandardName -like ' *intuneTemplate*' ) {
87103 $CompareGuid = $ComparisonItem.StandardName.Split (' .' ) | Select-Object - Index 2
88104 Write-Host " Extracted GUID: $CompareGuid "
89105 $Template = $AllIntuneTemplates | Where-Object { $_.GUID -like " *$CompareGuid *" }
90- if ($Template ) { $displayName = $Template.displayName }
106+ if ($Template ) {
107+ $displayName = $Template.displayName
108+ $standardDescription = $Template.description
109+ }
110+ }
111+ # Handle Conditional Access templates
112+ if ($ComparisonItem.StandardName -like ' *ConditionalAccessTemplate*' ) {
113+ $CompareGuid = $ComparisonItem.StandardName.Split (' .' ) | Select-Object - Index 2
114+ Write-Host " Extracted CA GUID: $CompareGuid "
115+ $Template = $AllCATemplates | Where-Object { $_.GUID -like " *$CompareGuid *" }
116+ if ($Template ) {
117+ $displayName = $Template.displayName
118+ $standardDescription = $Template.description
119+ }
91120 }
92121 $reason = if ($ExistingDriftStates.ContainsKey ($ComparisonItem.StandardName )) { $ExistingDriftStates [$ComparisonItem.StandardName ].Reason }
93122 $User = if ($ExistingDriftStates.ContainsKey ($ComparisonItem.StandardName )) { $ExistingDriftStates [$ComparisonItem.StandardName ].User }
94123 $StandardsDeviations.Add ([PSCustomObject ]@ {
95124 standardName = $ComparisonItem.StandardName
96125 standardDisplayName = $displayName
126+ standardDescription = $standardDescription
97127 expectedValue = ' Compliant'
98128 receivedValue = $ComparisonItem.StandardValue
99129 state = ' current'
@@ -203,14 +233,6 @@ function Get-CIPPDrift {
203233 # Get actual CA templates from templates table
204234 if ($CATemplateIds.Count -gt 0 ) {
205235 try {
206- $CATable = Get-CippTable - tablename ' templates'
207- $CAFilter = " PartitionKey eq 'CATemplate'"
208- $AllCATemplates = (Get-CIPPAzDataTableEntity @CATable - Filter $CAFilter ) | ForEach-Object {
209- $data = $_.JSON | ConvertFrom-Json - Depth 100
210- $data | Add-Member - NotePropertyName ' GUID' - NotePropertyValue $_.GUID - Force
211- $data
212- } | Sort-Object - Property displayName
213-
214236 $TemplateCATemplates = $AllCATemplates | Where-Object { $_.GUID -in $CATemplateIds }
215237 } catch {
216238 Write-Warning " Failed to get CA templates: $ ( $_.Exception.Message ) "
0 commit comments