@@ -7,36 +7,52 @@ function Start-AuditLogProcessingOrchestrator {
7
7
param ()
8
8
Write-Information ' Starting audit log processing in batches of 1000, per tenant'
9
9
$WebhookCacheTable = Get-CippTable - TableName ' CacheWebhooks'
10
- $WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable
11
- $TenantGroups = $WebhookCache | Group-Object - Property PartitionKey
12
10
13
- if ($TenantGroups ) {
14
- Write-Information " Processing webhook cache for $ ( $TenantGroups.Count ) tenants"
15
- # Write-Warning "AuditLogJobs are: $($TenantGroups.Count) tenants. Tenants: $($TenantGroups.name | ConvertTo-Json -Compress) "
16
- # Write-Warning "Here are the groups: $($TenantGroups | ConvertTo-Json -Compress)"
17
- $ProcessQueue = New-CippQueueEntry - Name ' Audit Logs Process' - Reference ' AuditLogsProcess' - TotalTasks ($TenantGroups | Measure-Object - Property Count - Sum).Sum
18
- $ProcessBatch = foreach ($TenantGroup in $TenantGroups ) {
19
- $TenantFilter = $TenantGroup.Name
20
- $RowIds = @ ($TenantGroup.Group.RowKey )
21
- for ($i = 0 ; $i -lt $RowIds.Count ; $i += 1000 ) {
22
- Write-Host " Processing $TenantFilter with $ ( $RowIds.Count ) row IDs. We're processing id $ ( $RowIds [$i ]) to $ ( $RowIds [[Math ]::Min ($i + 999 , $RowIds.Count - 1 )]) "
23
- $BatchRowIds = $RowIds [$i .. ([Math ]::Min($i + 999 , $RowIds.Count - 1 ))]
24
- [PSCustomObject ]@ {
25
- TenantFilter = $TenantFilter
26
- RowIds = $BatchRowIds
27
- QueueId = $ProcessQueue.RowKey
28
- FunctionName = ' AuditLogTenantProcess'
11
+ $DataTableQuery = @ {
12
+ First = 20000
13
+ Skip = 0
14
+ }
15
+
16
+ do {
17
+ $WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable @DataTableQuery
18
+ $TenantGroups = $WebhookCache | Group-Object - Property PartitionKey
19
+
20
+ if ($TenantGroups ) {
21
+ Write-Information " Processing webhook cache for $ ( $TenantGroups.Count ) tenants"
22
+ # Write-Warning "AuditLogJobs are: $($TenantGroups.Count) tenants. Tenants: $($TenantGroups.name | ConvertTo-Json -Compress) "
23
+ # Write-Warning "Here are the groups: $($TenantGroups | ConvertTo-Json -Compress)"
24
+ $ProcessQueue = New-CippQueueEntry - Name ' Audit Logs Process' - Reference ' AuditLogsProcess' - TotalTasks ($TenantGroups | Measure-Object - Property Count - Sum).Sum
25
+ $ProcessBatch = foreach ($TenantGroup in $TenantGroups ) {
26
+ $TenantFilter = $TenantGroup.Name
27
+ $RowIds = @ ($TenantGroup.Group.RowKey )
28
+ for ($i = 0 ; $i -lt $RowIds.Count ; $i += 1000 ) {
29
+ Write-Host " Processing $TenantFilter with $ ( $RowIds.Count ) row IDs. We're processing id $ ( $RowIds [$i ]) to $ ( $RowIds [[Math ]::Min ($i + 999 , $RowIds.Count - 1 )]) "
30
+ $BatchRowIds = $RowIds [$i .. ([Math ]::Min($i + 999 , $RowIds.Count - 1 ))]
31
+ [PSCustomObject ]@ {
32
+ TenantFilter = $TenantFilter
33
+ RowIds = $BatchRowIds
34
+ QueueId = $ProcessQueue.RowKey
35
+ FunctionName = ' AuditLogTenantProcess'
36
+ }
29
37
}
30
38
}
31
- }
32
- if ($ProcessBatch ) {
33
- $ProcessInputObject = [PSCustomObject ]@ {
34
- OrchestratorName = ' AuditLogTenantProcess'
35
- Batch = @ ($ProcessBatch )
36
- SkipLog = $true
39
+ if ($ProcessBatch ) {
40
+ $ProcessInputObject = [PSCustomObject ]@ {
41
+ OrchestratorName = ' AuditLogTenantProcess'
42
+ Batch = @ ($ProcessBatch )
43
+ SkipLog = $true
44
+ }
45
+ Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($ProcessInputObject | ConvertTo-Json - Depth 5 - Compress)
46
+ Write-Information " Started audit log processing orchestration with $ ( $ProcessBatch.Count ) batches"
37
47
}
38
- Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($ProcessInputObject | ConvertTo-Json - Depth 5 - Compress)
39
- Write-Information " Started audit log processing orchestration with $ ( $ProcessBatch.Count ) batches"
40
48
}
41
- }
49
+
50
+ if ($WebhookCache.Count -lt 20000 ) {
51
+ Write-Information ' No more rows to process'
52
+ break
53
+ }
54
+ Write-Information " Processed $ ( $WebhookCache.Count ) rows"
55
+ $DataTableQuery.Skip += 20000
56
+ Write-Information " Getting next batch of $ ( $DataTableQuery.First ) rows"
57
+ } while ($WebhookCache.Count -eq 20000 )
42
58
}
0 commit comments