@@ -6,97 +6,69 @@ function Start-TableCleanup {
66 [CmdletBinding (SupportsShouldProcess = $true )]
77 param ()
88
9- $CleanupRules = @ (
9+ $Batch = @ (
1010 @ {
11+ FunctionName = ' TableCleanupTask'
12+ Type = ' CleanupRule'
13+ TableName = ' webhookTable'
1114 DataTableProps = @ {
12- Context = (Get-CIPPTable - tablename ' webhookTable' ).Context
1315 Property = @ (' PartitionKey' , ' RowKey' , ' ETag' , ' Resource' )
16+ First = 1000
1417 }
1518 Where = " `$ _.Resource -match '^Audit'"
1619 }
1720 @ {
21+ FunctionName = ' TableCleanupTask'
22+ Type = ' CleanupRule'
23+ TableName = ' AuditLogSearches'
1824 DataTableProps = @ {
19- Context = (Get-CIPPTable - tablename ' AuditLogSearches' ).Context
2025 Filter = " PartitionKey eq 'Search' and Timestamp lt datetime'$ ( (Get-Date ).AddHours(-12 ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ssZ' )) '"
2126 First = 10000
2227 Property = @ (' PartitionKey' , ' RowKey' , ' ETag' )
2328 }
2429 }
2530 @ {
31+ FunctionName = ' TableCleanupTask'
32+ Type = ' CleanupRule'
33+ TableName = ' CippFunctionStats'
2634 DataTableProps = @ {
27- Context = (Get-CIPPTable - tablename ' CippFunctionStats' ).Context
2835 Filter = " PartitionKey eq 'Durable' and Timestamp lt datetime'$ ( (Get-Date ).AddDays(-7 ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ssZ' )) '"
2936 First = 10000
3037 Property = @ (' PartitionKey' , ' RowKey' , ' ETag' )
3138 }
3239 }
3340 @ {
41+ FunctionName = ' TableCleanupTask'
42+ Type = ' CleanupRule'
43+ TableName = ' CippQueue'
3444 DataTableProps = @ {
35- Context = (Get-CIPPTable - tablename ' CippQueue' ).Context
3645 Filter = " PartitionKey eq 'CippQueue' and Timestamp lt datetime'$ ( (Get-Date ).AddDays(-7 ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ssZ' )) '"
3746 First = 10000
3847 Property = @ (' PartitionKey' , ' RowKey' , ' ETag' )
3948 }
4049 }
4150 @ {
51+ FunctionName = ' TableCleanupTask'
52+ Type = ' CleanupRule'
53+ TableName = ' CippQueueTasks'
4254 DataTableProps = @ {
43- Context = (Get-CIPPTable - tablename ' CippQueueTasks' ).Context
4455 Filter = " PartitionKey eq 'Task' and Timestamp lt datetime'$ ( (Get-Date ).AddDays(-7 ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ssZ' )) '"
4556 First = 10000
4657 Property = @ (' PartitionKey' , ' RowKey' , ' ETag' )
4758 }
4859 }
49- )
50-
51- $DeleteTables = @ (
52- ' knownlocationdb'
53- )
54-
55- if ($PSCmdlet.ShouldProcess (' Start-TableCleanup' , ' Starting Table Cleanup' )) {
56- foreach ($Table in $DeleteTables ) {
57- try {
58- $Table = Get-CIPPTable - tablename $Table
59- if ($Table ) {
60- Write-Information " Deleting table $ ( $Table.Context.TableName ) "
61- try {
62- Remove-AzDataTable - Context $Table.Context - Force
63- } catch {
64- # Write-LogMessage -API 'TableCleanup' -message "Failed to delete table $($Table.Context.TableName)" -sev Error -LogData (Get-CippException -Exception $_)
65- }
66- }
67- } catch {
68- Write-Information " Table $Table not found"
69- }
60+ @ {
61+ FunctionName = ' TableCleanupTask'
62+ Type = ' DeleteTable'
63+ Tables = @ (' knownlocationdb' )
7064 }
65+ )
7166
72- Write-Information ' Starting table cleanup'
73- foreach ($Rule in $CleanupRules ) {
74- if ($Rule.Where ) {
75- $Where = [scriptblock ]::Create($Rule.Where )
76- } else {
77- $Where = { $true }
78- }
79- $DataTableProps = $Rule.DataTableProps
80-
81- $CleanupCompleted = $false
82- do {
83- $Entities = Get-AzDataTableEntity @DataTableProps | Where-Object $Where
84- if ($Entities ) {
85- Write-Information " Removing $ ( $Entities.Count ) entities from $ ( $Rule.DataTableProps.Context.TableName ) "
86- try {
87- Remove-AzDataTableEntity - Context $DataTableProps.Context - Entity $Entities - Force
88- if ($DataTableProps.First -and $Entities.Count -lt $DataTableProps.First ) {
89- $CleanupCompleted = $true
90- }
91- } catch {
92- Write-LogMessage - API ' TableCleanup' - message " Failed to remove entities from $ ( $DataTableProps.Context.TableName ) " - sev Error - LogData (Get-CippException - Exception $_ )
93- $CleanupCompleted = $true
94- }
95- } else {
96- $CleanupCompleted = $true
97- }
98- } while (! $CleanupCompleted )
99- }
100- Write-Information ' Table cleanup complete'
67+ $InputObject = @ {
68+ Batch = @ ($Batch )
69+ OrchestratorName = ' TableCleanup'
70+ SkipLog = $true
10171 }
72+
73+ Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
10274}
0 commit comments