Skip to content

Commit 6ac8021

Browse files
Add delete CA
1 parent 1b6cedd commit 6ac8021

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,21 @@ function Invoke-ExecUpdateDriftDeviation {
7272
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Scheduled drift remediation task for $Setting" -Sev 'Info'
7373
}
7474
if ($Deviation.status -eq 'deniedDelete') {
75-
#Here we look at the policy ID received and the type, and nuke it.
75+
if ($Deviation.standardName -like 'ConditionalAccessTemplate*') {
76+
$ID = $Deviation.standardName -replace 'ConditionalAccessTemplates.', ''
77+
Write-Host "Going to delete CA Policy with ID $ID. Deviation Name is $($Deviation.standardName)"
78+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies/$($ID)" -type DELETE -tenant $TenantFilter -asapp $true
79+
"Deleted CA Policy $($ID)"
80+
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Deleted Conditional Access Policy with ID $($ID)" -Sev 'Info'
81+
}
82+
83+
if ($Deviation.standardName -like 'IntuneTemplates*') {
84+
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$($UrlName)('$($PolicyId)')" -type DELETE -tenant $TenantFilter
85+
"Deleted Intune Policy $($ID)"
86+
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Deleted Intune Policy with ID $($ID)" -Sev 'Info'
87+
88+
}
89+
7690
}
7791
} catch {
7892
[PSCustomObject]@{

0 commit comments

Comments
 (0)