Skip to content

Commit

Permalink
Merge pull request #31 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Jan 27, 2025
2 parents d1e2ffe + e81811d commit bca1a21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ function Invoke-ListGraphRequest {
$Results = Get-GraphRequestList @GraphRequestParams
if ($Results.nextLink) {
Write-Host "NextLink: $($Results.nextLink | Select-Object -Last 1)"
$Metadata['nextLink'] = $Results.nextLink | Select-Object -Last 1
if ($Request.Query.TenantFilter -ne 'AllTenants') {
$Metadata['nextLink'] = $Results.nextLink | Select-Object -Last 1
}
#Results is an array of objects, so we need to remove the last object before returning
$Results = $Results | Select-Object -First ($Results.Count - 1)
}
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function Get-GraphRequestList {
TenantFilter = $_.defaultDomainName
Endpoint = $using:Endpoint
Parameters = $using:Parameters
NoPagination = $using:NoPagination.IsPresent
NoPagination = $false
ReverseTenantLookupProperty = $using:ReverseTenantLookupProperty
ReverseTenantLookup = $using:ReverseTenantLookup.IsPresent
NoAuthCheck = $using:NoAuthCheck.IsPresent
Expand Down

0 comments on commit bca1a21

Please sign in to comment.