Skip to content

Commit 984a328

Browse files
committed
limit graph renewals to active tenants
1 parent 373274e commit 984a328

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Modules/CIPPCore/Public/Webhooks/Invoke-CIPPGraphWebhookRenewal.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ function Invoke-CippGraphWebhookRenewal {
44
'expirationDateTime' = "$RenewalDate"
55
} | ConvertTo-Json
66

7+
$Tenants = Get-Tenants -IncludeErrors
8+
79
$WebhookTable = Get-CIPPTable -TableName webhookTable
810
try {
911
$WebhookData = Get-AzDataTableEntity @WebhookTable | Where-Object { $null -ne $_.SubscriptionID -and $_.SubscriptionID -ne '' -and ((Get-Date($_.Expiration)) -le ((Get-Date).AddHours(2))) }
@@ -16,6 +18,12 @@ function Invoke-CippGraphWebhookRenewal {
1618
foreach ($UpdateSub in $WebhookData) {
1719
try {
1820
$TenantFilter = $UpdateSub.PartitionKey
21+
if ($Tenants.defaultDomainName -notcontains $TenantFilter -and $Tenants.customerId -notcontains $TenantFilter) {
22+
Write-LogMessage -API 'Renew_Graph_Subscriptions' -message "Removing Subscription Renewal for $($UpdateSub.SubscriptionID) as tenant $TenantFilter is not in the tenant list." -Sev 'Warning' -tenant $TenantFilter
23+
Remove-AzDataTableEntity -Force @WebhookTable -Entity $UpdateSub
24+
continue
25+
}
26+
1927
try {
2028
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($UpdateSub.SubscriptionID)" -tenantid $TenantFilter -type PATCH -body $body -Verbose
2129
$UpdateSub.Expiration = $RenewalDate

0 commit comments

Comments
 (0)