Skip to content

Commit 994098c

Browse files
committed
fix: Update Invoke-ExecRestoreBackup to handle Azure Table column types correctly during backup restoration
1 parent 1a10684 commit 994098c

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ function Invoke-ExecRestoreBackup {
99
param($Request, $TriggerMetadata)
1010

1111
$APIName = $Request.Params.CIPPEndpoint
12+
13+
# Types natively supported by Azure Table Storage — preserve these as-is
14+
$AzureTableTypes = @(
15+
[string], [int], [long], [double], [bool], [datetime], [guid], [byte[]]
16+
)
1217
$RestrictedTables = @('AccessRoleGroups', 'CustomRoles') # tables that require superadmin to restore
1318

1419
# Resolve the calling user's roles, including Entra group-based roles
@@ -60,7 +65,10 @@ function Invoke-ExecRestoreBackup {
6065
}
6166
$Table = Get-CippTable -tablename $_.table
6267
$ht2 = @{}
63-
$_.psobject.properties | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
68+
$_.psobject.properties | Where-Object { $_.Name -ne 'table' } | ForEach-Object {
69+
$val = $_.Value
70+
$ht2[$_.Name] = if ($null -ne $val -and $AzureTableTypes -contains $val.GetType()) { $val } else { [string]$val }
71+
}
6472
$Table.Entity = $ht2
6573
Add-AzDataTableEntity @Table -Force
6674
$RestoredCount++
@@ -86,7 +94,10 @@ function Invoke-ExecRestoreBackup {
8694
}
8795
$Table = Get-CippTable -tablename $line.table
8896
$ht2 = @{}
89-
$line.psobject.properties | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
97+
$line.psobject.properties | Where-Object { $_.Name -ne 'table' } | ForEach-Object {
98+
$val = $_.Value
99+
$ht2[$_.Name] = if ($null -ne $val -and $AzureTableTypes -contains $val.GetType()) { $val } else { [string]$val }
100+
}
90101
$Table.Entity = $ht2
91102
Add-AzDataTableEntity @Table -Force
92103
$RestoredCount++

0 commit comments

Comments
 (0)