@@ -29,6 +29,24 @@ function Get-CIPPDrift {
2929 [switch ]$AllTenants
3030 )
3131
32+
33+ $IntuneTable = Get-CippTable - tablename ' templates'
34+ $IntuneFilter = " PartitionKey eq 'IntuneTemplate'"
35+ $RawIntuneTemplates = (Get-CIPPAzDataTableEntity @IntuneTable - Filter $IntuneFilter )
36+ $AllIntuneTemplates = $RawIntuneTemplates | ForEach-Object {
37+ try {
38+ $JSONData = $_.JSON | ConvertFrom-Json - Depth 100 - ErrorAction SilentlyContinue
39+ $data = $JSONData.RAWJson | ConvertFrom-Json - Depth 100 - ErrorAction SilentlyContinue
40+ $data | Add-Member - NotePropertyName ' displayName' - NotePropertyValue $JSONData.Displayname - Force
41+ $data | Add-Member - NotePropertyName ' description' - NotePropertyValue $JSONData.Description - Force
42+ $data | Add-Member - NotePropertyName ' Type' - NotePropertyValue $JSONData.Type - Force
43+ $data | Add-Member - NotePropertyName ' GUID' - NotePropertyValue $_.RowKey - Force
44+ $data
45+ } catch {
46+ # Skip invalid templates
47+ }
48+ } | Sort-Object - Property displayName
49+
3250 try {
3351 $AlignmentData = Get-CIPPTenantAlignment - TenantFilter $TenantFilter - TemplateId $TemplateId | Where-Object - Property standardType -EQ ' drift'
3452 if (-not $AlignmentData ) {
@@ -64,16 +82,24 @@ function Get-CIPPDrift {
6482 } else {
6583 ' New'
6684 }
85+ # 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
86+ if ($ComparisonItem.StandardName -like ' *intuneTemplate*' ) {
87+ $CompareGuid = $ComparisonItem.StandardName.Split (' .' ) | Select-Object - Index 2
88+ Write-Host " Extracted GUID: $CompareGuid "
89+ $Template = $AllIntuneTemplates | Where-Object { $_.GUID -like " *$CompareGuid *" }
90+ if ($Template ) { $displayName = $Template.displayName }
91+ }
6792 $reason = if ($ExistingDriftStates.ContainsKey ($ComparisonItem.StandardName )) { $ExistingDriftStates [$ComparisonItem.StandardName ].Reason }
6893 $User = if ($ExistingDriftStates.ContainsKey ($ComparisonItem.StandardName )) { $ExistingDriftStates [$ComparisonItem.StandardName ].User }
6994 $StandardsDeviations.Add ([PSCustomObject ]@ {
70- standardName = $ComparisonItem.StandardName
71- expectedValue = ' Compliant'
72- receivedValue = $ComparisonItem.StandardValue
73- state = ' current'
74- Status = $Status
75- Reason = $reason
76- lastChangedByUser = $User
95+ standardName = $ComparisonItem.StandardName
96+ standardDisplayName = $displayName
97+ expectedValue = ' Compliant'
98+ receivedValue = $ComparisonItem.StandardValue
99+ state = ' current'
100+ Status = $Status
101+ Reason = $reason
102+ lastChangedByUser = $User
77103 })
78104 }
79105 }
@@ -194,22 +220,6 @@ function Get-CIPPDrift {
194220 # Get actual Intune templates from templates table
195221 if ($IntuneTemplateIds.Count -gt 0 ) {
196222 try {
197- $IntuneTable = Get-CippTable - tablename ' templates'
198- $IntuneFilter = " PartitionKey eq 'IntuneTemplate'"
199- $RawIntuneTemplates = (Get-CIPPAzDataTableEntity @IntuneTable - Filter $IntuneFilter )
200- $AllIntuneTemplates = $RawIntuneTemplates | ForEach-Object {
201- try {
202- $JSONData = $_.JSON | ConvertFrom-Json - Depth 100 - ErrorAction SilentlyContinue
203- $data = $JSONData.RAWJson | ConvertFrom-Json - Depth 100 - ErrorAction SilentlyContinue
204- $data | Add-Member - NotePropertyName ' displayName' - NotePropertyValue $JSONData.Displayname - Force
205- $data | Add-Member - NotePropertyName ' description' - NotePropertyValue $JSONData.Description - Force
206- $data | Add-Member - NotePropertyName ' Type' - NotePropertyValue $JSONData.Type - Force
207- $data | Add-Member - NotePropertyName ' GUID' - NotePropertyValue $_.RowKey - Force
208- $data
209- } catch {
210- # Skip invalid templates
211- }
212- } | Sort-Object - Property displayName
213223
214224 $TemplateIntuneTemplates = $AllIntuneTemplates | Where-Object { $_.GUID -in $IntuneTemplateIds }
215225 } catch {
@@ -222,7 +232,6 @@ function Get-CIPPDrift {
222232 $PolicyFound = $false
223233 $tenantPolicy.policy | Add-Member - MemberType NoteProperty - Name ' URLName' - Value $TenantPolicy.Type - Force
224234 $TenantPolicyName = if ($TenantPolicy.Policy.displayName ) { $TenantPolicy.Policy.displayName } else { $TenantPolicy.Policy.name }
225-
226235 foreach ($TemplatePolicy in $TemplateIntuneTemplates ) {
227236 $TemplatePolicyName = if ($TemplatePolicy.displayName ) { $TemplatePolicy.displayName } else { $TemplatePolicy.name }
228237
0 commit comments