Skip to content

Commit 2000fda

Browse files
authored
Merge pull request #507 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents b30b34b + 63ff49a commit 2000fda

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
function Add-CIPPAzDataTableEntity {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
#>
26
[CmdletBinding(DefaultParameterSetName = 'OperationType')]
37
param(
48
$Context,
@@ -13,6 +17,16 @@ function Add-CIPPAzDataTableEntity {
1317
[string]$OperationType = 'Add'
1418
)
1519

20+
# Validate input parameters
21+
if ($null -eq $Context) {
22+
throw 'Context parameter cannot be null'
23+
}
24+
25+
if ($null -eq $Entity) {
26+
Write-Warning 'Entity parameter is null - nothing to process'
27+
return
28+
}
29+
1630
$Parameters = @{
1731
Context = $Context
1832
CreateTableIfNotExists = $CreateTableIfNotExists
@@ -28,16 +42,55 @@ function Add-CIPPAzDataTableEntity {
2842

2943
foreach ($SingleEnt in @($Entity)) {
3044
try {
45+
# Skip null entities
46+
if ($null -eq $SingleEnt) {
47+
Write-Warning 'Skipping null entity'
48+
continue
49+
}
50+
3151
if ($null -eq $SingleEnt.PartitionKey -or $null -eq $SingleEnt.RowKey) {
3252
throw 'PartitionKey or RowKey is null'
3353
}
3454

55+
# Ensure entity is not empty
56+
if ($SingleEnt -is [hashtable] -and $SingleEnt.Count -eq 0) {
57+
Write-Warning 'Skipping empty hashtable entity'
58+
continue
59+
} elseif ($SingleEnt -is [PSCustomObject] -and ($SingleEnt.PSObject.Properties | Measure-Object).Count -eq 0) {
60+
Write-Warning 'Skipping empty PSCustomObject entity'
61+
continue
62+
}
63+
64+
# Additional validation for AzBobbyTables compatibility
65+
try {
66+
# Ensure all property values are not null for string properties
67+
if ($SingleEnt -is [hashtable]) {
68+
foreach ($key in @($SingleEnt.Keys)) {
69+
if ($null -eq $SingleEnt[$key]) {
70+
$SingleEnt.Remove($key)
71+
}
72+
}
73+
} elseif ($SingleEnt -is [PSCustomObject]) {
74+
$propsToRemove = [system.Collections.Generic.List[string]]::new()
75+
foreach ($prop in $SingleEnt.PSObject.Properties) {
76+
if ($null -eq $prop.Value) {
77+
$propsToRemove.Add($prop.Name)
78+
}
79+
}
80+
foreach ($propName in $propsToRemove) {
81+
$SingleEnt.PSObject.Properties.Remove($propName)
82+
}
83+
}
84+
} catch {
85+
Write-Warning "Error during entity validation: $($_.Exception.Message)"
86+
}
87+
3588
Add-AzDataTableEntity @Parameters -Entity $SingleEnt -ErrorAction Stop
3689

3790
} catch [System.Exception] {
3891
if ($_.Exception.ErrorCode -in @('PropertyValueTooLarge', 'EntityTooLarge', 'RequestBodyTooLarge')) {
3992
try {
40-
Write-Host 'Entity is too large. Splitting entity into multiple parts.'
93+
Write-Information 'Entity is too large. Splitting entity into multiple parts.'
4194

4295
$largePropertyNames = [System.Collections.Generic.List[string]]::new()
4396
$entitySize = 0
@@ -173,11 +226,13 @@ function Add-CIPPAzDataTableEntity {
173226
} catch {
174227
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
175228
Write-Warning 'AzBobbyTables Error'
176-
Write-Information ($SingleEnt | ConvertTo-Json)
177229
throw "Error processing entity: $ErrorMessage Linenumber: $($_.InvocationInfo.ScriptLineNumber)"
178230
}
179231
} else {
232+
Write-Information ($_.Exception | ConvertTo-Json)
180233
Write-Information "THE ERROR IS $($_.Exception.message). The size of the entity is $entitySize."
234+
Write-Information "Parameters are: $($Parameters | ConvertTo-Json -Compress)"
235+
Write-Information $_.InvocationInfo.PositionMessage
181236
throw $_
182237
}
183238
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ListIntuneTemplates.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Invoke-ListIntuneTemplates {
8484

8585
return ([HttpResponseContext]@{
8686
StatusCode = [HttpStatusCode]::OK
87-
Body = ($Templates | ConvertTo-Json -Depth 100)
87+
Body = ConvertTo-Json -Depth 100 -InputObject @($Templates)
8888
})
8989

9090
}

0 commit comments

Comments
 (0)