From b8d13a28b9c8f448d8ea5e5f640b6e841d569c5d Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 27 Jan 2025 10:48:57 -0500 Subject: [PATCH 1/2] fix pagination for AllTenants queries --- .../HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1 | 4 +++- .../CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1 index 84de0b74395a..45bede27c0b2 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1 @@ -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) } diff --git a/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 b/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 index 0d376eda8f9a..98d09f7507c9 100644 --- a/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 +++ b/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 @@ -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 From e81811d31d126b756a7298c9f813032ed2abe771 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 27 Jan 2025 12:35:37 -0500 Subject: [PATCH 2/2] Add UnsubscribeAll to ExecWebhookSubscriptions --- .../Invoke-ExecWebhookSubscriptions.ps1 | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecWebhookSubscriptions.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecWebhookSubscriptions.ps1 index 86359bdd9572..c5cf687c5fc9 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecWebhookSubscriptions.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecWebhookSubscriptions.ps1 @@ -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)'"