Skip to content

Commit

Permalink
added all tenants support
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Aug 8, 2023
1 parent f5c7173 commit 028243b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 17 additions & 2 deletions AddAlert/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,23 @@ $Results = foreach ($Tenant in $tenants) {
Add-AzDataTableEntity @Table -Entity $CompleteObject -Force

$URL = ($request.headers.'x-ms-original-url').split('/api') | Select-Object -First 1
Write-Host $URL
foreach ($eventype in $Request.body.EventTypes.value) {
if ($Tenant -eq 'AllTenants') {
Get-Tenants | ForEach-Object {
foreach ($eventype in $Request.body.EventTypes.value) {
$params = @{
TenantFilter = $_.defaultDomainName
auditLogAPI = $true
operations = ($Request.body.Operations.value -join ',')
allowedLocations = ($Request.body.AllowedLocations.value -join ',')
BaseURL = $URL
EventType = $eventype
ExecutingUser = $Request.headers.'x-ms-client-principal'
}
New-CIPPGraphSubscription @params
}
}
}
else {
$params = @{
TenantFilter = $tenant
auditLogAPI = $true
Expand Down
9 changes: 7 additions & 2 deletions Modules/CIPPCore/Public/Remove-CIPPGraphSubscription.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ function Remove-CIPPGraphSubscription {
$WebhookTable = Get-CIPPTable -TableName webhookTable
$WebhookRow = Get-AzDataTableEntity @WebhookTable | Where-Object { $_.RowKey -eq $CIPPID }
if ($WebhookRow.Resource -eq "M365AuditLogs") {
$AuditLog = New-GraphPOSTRequest -uri "https://manage.office.com/api/v1.0/$($TenantFilter)/activity/feed/subscriptions/stop?contentType=$($WebhookRow.EventType)" -scope "https://manage.office.com/.default" -tenantid $TenantFilter -type POST -body "{}" -verbose

try {
$AuditLog = New-GraphPOSTRequest -uri "https://manage.office.com/api/v1.0/$($TenantFilter)/activity/feed/subscriptions/stop?contentType=$($WebhookRow.EventType)" -scope "https://manage.office.com/.default" -tenantid $TenantFilter -type POST -body "{}" -verbose
}
catch {
#allowed to fail if the subscription is already removed
}
$null = Remove-AzDataTableEntity @WebhookTable -Entity $WebhookRow
}
else {
$OldID = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/subscriptions" -tenantid $TenantFilter) | Where-Object { $_.notificationUrl -eq $WebhookRow.WebhookNotificationUrl }
Expand Down

0 comments on commit 028243b

Please sign in to comment.