Skip to content

Commit 038e3e8

Browse files
committed
Add Reason and lastChangedByUser to policy deviations
Extended the policy deviation objects in Get-CIPPDrift to include Reason and lastChangedByUser fields when available from existing drift states. This provides more context about policy changes and their origins.
1 parent 1ef9db9 commit 038e3e8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,17 @@ function Get-CIPPDrift {
280280
} else {
281281
'New'
282282
}
283+
$reason = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].Reason }
284+
$User = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].User }
283285
$PolicyDeviation = [PSCustomObject]@{
284286
standardName = $PolicyKey
285287
standardDisplayName = "Intune - $TenantPolicyName"
286288
expectedValue = 'This policy only exists in the tenant, not in the template.'
287289
receivedValue = $TenantPolicy.Policy
288290
state = 'current'
289291
Status = $Status
292+
Reason = $reason
293+
lastChangedByUser = $User
290294
}
291295
$PolicyDeviations.Add($PolicyDeviation)
292296
}
@@ -310,13 +314,17 @@ function Get-CIPPDrift {
310314
} else {
311315
'New'
312316
}
317+
$reason = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].Reason }
318+
$User = if ($ExistingDriftStates.ContainsKey($PolicyKey)) { $ExistingDriftStates[$PolicyKey].User }
313319
$PolicyDeviation = [PSCustomObject]@{
314320
standardName = $PolicyKey
315321
standardDisplayName = "Conditional Access - $($TenantCAPolicy.displayName)"
316322
expectedValue = 'This policy only exists in the tenant, not in the template.'
317323
receivedValue = $TenantCAPolicy | Out-String
318324
state = 'current'
319325
Status = $Status
326+
Reason = $reason
327+
lastChangedByUser = $User
320328
}
321329
$PolicyDeviations.Add($PolicyDeviation)
322330
}

0 commit comments

Comments
 (0)