Skip to content

Commit 80cb475

Browse files
authored
Merge pull request #893 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 7a4f03a + 18d28ec commit 80cb475

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ExecUpdateDriftDeviation.ps1

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,28 @@ function Invoke-ExecUpdateDriftDeviation {
4646
if ($Setting -like '*IntuneTemplate*') {
4747
$Setting = 'IntuneTemplate'
4848
$TemplateId = $Deviation.standardName.split('.') | Select-Object -Index 2
49-
$StandardTemplate = $StandardTemplate.standardSettings.IntuneTemplate | Where-Object { $_.TemplateList.value -like "*$TemplateId*" }
50-
$StandardTemplate | Add-Member -MemberType NoteProperty -Name 'remediate' -Value $true -Force
51-
$StandardTemplate | Add-Member -MemberType NoteProperty -Name 'report' -Value $true -Force
52-
$Settings = $StandardTemplate
49+
$MatchedTemplate = $StandardTemplate.standardSettings.IntuneTemplate | Where-Object { $_.TemplateList.value -like "*$TemplateId*" } | Select-Object -First 1
50+
if (-not $MatchedTemplate) {
51+
# Template may be inside a TemplateList-Tags bundle, expand it
52+
$BundleEntry = $StandardTemplate.standardSettings.IntuneTemplate | Where-Object {
53+
$_.'TemplateList-Tags'.rawData.templates | Where-Object { $_.GUID -like "*$TemplateId*" }
54+
} | Select-Object -First 1
55+
if ($BundleEntry) {
56+
$MatchedTemplate = $BundleEntry.PSObject.Copy()
57+
$MatchedTemplate.PSObject.Properties.Remove('TemplateList-Tags')
58+
$MatchedTemplate | Add-Member -NotePropertyName TemplateList -NotePropertyValue ([pscustomobject]@{
59+
label = $TemplateId
60+
value = $TemplateId
61+
}) -Force
62+
}
63+
}
64+
if (-not $MatchedTemplate) {
65+
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Could not find IntuneTemplate $TemplateId in drift standard settings for remediation" -Sev 'Warn'
66+
} else {
67+
$MatchedTemplate | Add-Member -MemberType NoteProperty -Name 'remediate' -Value $true -Force
68+
$MatchedTemplate | Add-Member -MemberType NoteProperty -Name 'report' -Value $true -Force
69+
$Settings = $MatchedTemplate
70+
}
5371
} elseif ($Setting -like '*ConditionalAccessTemplate*') {
5472
$Setting = 'ConditionalAccessTemplate'
5573
$TemplateId = $Deviation.standardName.split('.') | Select-Object -Index 2
@@ -91,7 +109,7 @@ function Invoke-ExecUpdateDriftDeviation {
91109
}
92110
}
93111
Add-CIPPScheduledTask -Task $TaskBody -hidden $false
94-
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Scheduled drift remediation task for $Setting" -Sev 'Info'
112+
Write-LogMessage -tenant $TenantFilter -Headers $Request.Headers -API $APINAME -message "Scheduled drift remediation task for $Setting" -Sev 'Info'
95113

96114
if ($PersistentDeny) {
97115
$PersistentTaskBody = @{

0 commit comments

Comments
 (0)