Skip to content

Commit f8aea6b

Browse files
committed
support operationtype
1 parent 1027be5 commit f8aea6b

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
function Add-CIPPAzDataTableEntity {
2-
[CmdletBinding()]
2+
[CmdletBinding(DefaultParameterSetName = 'OperationType')]
33
param(
44
$Context,
55
$Entity,
6+
[switch]$CreateTableIfNotExists,
7+
8+
[Parameter(ParameterSetName = 'Force')]
69
[switch]$Force,
7-
[switch]$CreateTableIfNotExists
10+
11+
[Parameter(ParameterSetName = 'OperationType')]
12+
[ValidateSet('Add', 'UpsertMerge', 'UpsertReplace')]
13+
[string]$OperationType = 'Add'
814
)
915

16+
$Parameters = @{
17+
Context = $Context
18+
CreateTableIfNotExists = $CreateTableIfNotExists
19+
}
20+
if ($PSCmdlet.ParameterSetName -eq 'Force') {
21+
$Parameters.Force = $Force
22+
} else {
23+
$Parameters.OperationType = $OperationType
24+
}
25+
1026
$MaxRowSize = 500000 - 100 # Maximum size of an entity
1127
$MaxSize = 30kb # Maximum size of a property value
1228

@@ -15,7 +31,7 @@ function Add-CIPPAzDataTableEntity {
1531
if ($null -eq $SingleEnt.PartitionKey -or $null -eq $SingleEnt.RowKey) {
1632
throw 'PartitionKey or RowKey is null'
1733
}
18-
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $SingleEnt -ErrorAction Stop
34+
Add-AzDataTableEntity @Parameters -Entity $SingleEnt -ErrorAction Stop
1935
} catch [System.Exception] {
2036
if ($_.Exception.ErrorCode -eq 'PropertyValueTooLarge' -or $_.Exception.ErrorCode -eq 'EntityTooLarge' -or $_.Exception.ErrorCode -eq 'RequestBodyTooLarge') {
2137
try {
@@ -138,16 +154,16 @@ function Add-CIPPAzDataTableEntity {
138154
foreach ($row in $rows) {
139155
Write-Information "current entity is $($row.RowKey) with $($row.PartitionKey). Our size is $([System.Text.Encoding]::UTF8.GetByteCount($($row | ConvertTo-Json -Compress)))"
140156
$NewRow = [PSCustomObject]$row
141-
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $NewRow
157+
Add-AzDataTableEntity @Parameters -Entity $NewRow
142158
}
143159
} else {
144160
$NewEnt = [PSCustomObject]$SingleEnt
145-
Add-AzDataTableEntity -Context $Context -Force:$Force -CreateTableIfNotExists:$CreateTableIfNotExists -Entity $NewEnt
161+
Add-AzDataTableEntity @Parameters -Entity $NewEnt
146162
}
147163

148164
} catch {
149165
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
150-
Write-Warning ("AzBobbyTables Error")
166+
Write-Warning ('AzBobbyTables Error')
151167
Write-Information ($SingleEnt | ConvertTo-Json)
152168
throw "Error processing entity: $ErrorMessage Linenumber: $($_.InvocationInfo.ScriptLineNumber)"
153169
}

0 commit comments

Comments
 (0)