@@ -7,7 +7,12 @@ function Start-AuditLogSearchCreation {
77 param ()
88 try {
99 $ConfigTable = Get-CippTable - TableName ' WebhookRules'
10- $ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable - Filter " PartitionKey eq 'Webhookv2'"
10+ $ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable - Filter " PartitionKey eq 'Webhookv2'" | ForEach-Object {
11+ $ConfigEntry = $_
12+ $ConfigEntry.excludedTenants = $ConfigEntry.excludedTenants | ConvertFrom-Json
13+ $ConfigEntry.Tenants = $ConfigEntry.Tenants | ConvertFrom-Json
14+ $ConfigEntry
15+ }
1116
1217 $TenantList = Get-Tenants - IncludeErrors
1318 # Round time down to nearest minute
@@ -16,11 +21,29 @@ function Start-AuditLogSearchCreation {
1621 $EndTime = $Now.AddSeconds (- $Now.Seconds )
1722
1823 Write-Information ' Audit Logs: Creating new searches'
24+
1925 foreach ($Tenant in $TenantList ) {
20- $TenantsList = Expand-CIPPTenantGroups - TenantFilter ($ConfigEntries.Tenants | ConvertFrom-Json )
21- $Configuration = $ConfigEntries | Where-Object { ($_.Tenants -match $TenantFilter -or $_.Tenants -match ' AllTenants' ) }
22- if ($Configuration -and $Tenant -in $TenantsList ) {
23- $ServiceFilters = $Configuration | Select-Object - Property type | Sort-Object - Property type - Unique | ForEach-Object { $_.type.split (' .' )[1 ] }
26+ Write-Information " Processing tenant $ ( $Tenant.defaultDomainName ) - $ ( $Tenant.customerId ) "
27+ $TenantInConfig = $false
28+ $MatchingConfigs = [System.Collections.Generic.List [object ]]::new()
29+ foreach ($ConfigEntry in $ConfigEntries ) {
30+ if ($ConfigEntry.excludedTenants.value -contains $Tenant.defaultDomainName ) {
31+ continue
32+ }
33+ $TenantsList = Expand-CIPPTenantGroups - TenantFilter ($ConfigEntry.Tenants )
34+ if ($TenantsList.value -contains $Tenant.defaultDomainName -or $TenantsList.value -contains ' AllTenants' ) {
35+ $TenantInConfig = $true
36+ $MatchingConfigs.Add ($ConfigEntry )
37+ }
38+ }
39+
40+ if (! $TenantInConfig ) {
41+ Write-Information " Tenant $ ( $Tenant.defaultDomainName ) has no configured audit log rules, skipping search creation."
42+ continue
43+ }
44+
45+ if ($MatchingConfigs ) {
46+ $ServiceFilters = $MatchingConfigs | Select-Object - Property type | Sort-Object - Property type - Unique | ForEach-Object { $_.type.split (' .' )[1 ] }
2447 try {
2548 $LogSearch = @ {
2649 StartTime = $StartTime
0 commit comments