Skip to content

Commit

Permalink
Added removal of auditlog subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jul 30, 2023
1 parent 6c296d9 commit c04b65d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Modules/CIPPCore/Public/Remove-CIPPGraphSubcription.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ function Remove-CIPPGraphSubscription {
try {
$WebhookTable = Get-CIPPTable -TableName webhookTable
$WebhookRow = Get-AzDataTableEntity @WebhookTable | Where-Object { $_.RowKey -eq $CIPPID }
$OldID = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/subscriptions" -tenantid $TenantFilter) | Where-Object { $_.notificationUrl -eq $WebhookRow.WebhookNotificationUrl }
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($oldId.ID)" -tenantid $TenantFilter -type DELETE -body {} -Verbose
$null = Remove-AzDataTableEntity @WebhookTable -Entity $WebhookRow
if ($WebhookRow.Resource -eq "M365AuditLogs") {
$AuditLog = New-GraphPOSTRequest -uri "https://manage.office.com/api/v1.0/$($TenantFilter)/activity/feed/subscriptions/stop?contentType=$($WebhookRow.EventType)" -tenantid $TenantFilter -type POST -body "{}" -verbose

}
else {
$OldID = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/subscriptions" -tenantid $TenantFilter) | Where-Object { $_.notificationUrl -eq $WebhookRow.WebhookNotificationUrl }
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($oldId.ID)" -tenantid $TenantFilter -type DELETE -body {} -Verbose
$null = Remove-AzDataTableEntity @WebhookTable -Entity $WebhookRow
}
return "Remove webhook subscription to $($GraphRequest.value.notificationUrl)"

}
Expand Down

0 comments on commit c04b65d

Please sign in to comment.