Skip to content

Commit

Permalink
Add UnsubscribeAll to ExecWebhookSubscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Jan 27, 2025
1 parent b8d13a2 commit e81811d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ function Invoke-ExecWebhookSubscriptions {
})
}
}
'UnsubscribeAll' {
$TenantList = Get-Tenants -IncludeErrors
$Results = foreach ($tenant in $TenantList) {
$TenantFilter = $tenant.defaultDomainName
$Subscriptions = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscriptions' -tenantid $TenantFilter | Where-Object { $_.notificationUrl -like '*PublicWebhooks*' }
"Unsubscribing from all CIPP subscriptions for $TenantFilter - $($Subscriptions.Count) subscriptions found"
$Subscriptions | ForEach-Object {
New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($_.id)" -tenantid $TenantFilter -type DELETE -body {} -Verbose
# get row from table if exists and remove
$Webhook = Get-AzDataTableEntity @Table -Filter "WebhookNotificationUrl eq 'https://graph.microsoft.com/beta/subscriptions/$($_.id)'" -Property PartitionKey, RowKey, ETag
if ($Webhook) {
$null = Remove-AzDataTableEntity -Force @Table -Entity $Webhook
}
}
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ Results = $Results }
})
}
'Resubscribe' {
Write-Host "Resubscribing to $($Request.Query.WebhookID)"
$Row = Get-AzDataTableEntity @Table -Filter "RowKey eq '$($Request.Query.WebhookID)'"
Expand Down

0 comments on commit e81811d

Please sign in to comment.