Skip to content

Commit 4ff8732

Browse files
maximum kilobytes of internet(fixes remove empty array and returns it to KelvinCode
1 parent 7f1ed60 commit 4ff8732

2 files changed

Lines changed: 5 additions & 36 deletions

File tree

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,19 @@
1-
function Remove-EmptyArrays {
2-
<#
3-
.SYNOPSIS
4-
Recursively removes empty arrays and null properties from objects
5-
.DESCRIPTION
6-
This function recursively traverses an object (Array, Hashtable, or PSCustomObject) and removes:
7-
- Empty arrays
8-
- Null properties
9-
The function modifies the object in place.
10-
.PARAMETER Object
11-
The object to process (can be Array, Hashtable, or PSCustomObject)
12-
.FUNCTIONALITY
13-
Internal
14-
.EXAMPLE
15-
$obj = @{ items = @(); name = "test"; value = $null }
16-
Remove-EmptyArrays -Object $obj
17-
.EXAMPLE
18-
$obj = [PSCustomObject]@{ items = @(); name = "test" }
19-
Remove-EmptyArrays -Object $obj
20-
#>
21-
[CmdletBinding()]
22-
param(
23-
[Parameter(Mandatory = $true)]
24-
[object]$Object
25-
)
26-
1+
function Remove-EmptyArrays ($Object) {
272
if ($Object -is [Array]) {
28-
foreach ($Item in $Object) {
29-
Remove-EmptyArrays -Object $Item
30-
}
3+
foreach ($Item in $Object) { Remove-EmptyArrays $Item }
314
} elseif ($Object -is [HashTable]) {
325
foreach ($Key in @($Object.get_Keys())) {
336
if ($Object[$Key] -is [Array] -and $Object[$Key].get_Count() -eq 0) {
347
$Object.Remove($Key)
35-
} else {
36-
Remove-EmptyArrays -Object $Object[$Key]
37-
}
8+
} else { Remove-EmptyArrays $Object[$Key] }
389
}
3910
} elseif ($Object -is [PSCustomObject]) {
4011
foreach ($Name in @($Object.PSObject.Properties.Name)) {
4112
if ($Object.$Name -is [Array] -and $Object.$Name.get_Count() -eq 0) {
4213
$Object.PSObject.Properties.Remove($Name)
4314
} elseif ($null -eq $Object.$Name) {
4415
$Object.PSObject.Properties.Remove($Name)
45-
} else {
46-
Remove-EmptyArrays -Object $Object.$Name
47-
}
16+
} else { Remove-EmptyArrays $Object.$Name }
4817
}
4918
}
5019
}

Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function New-CIPPCAPolicy {
8989
$displayName = ($RawJSON | ConvertFrom-Json).displayName
9090

9191
$JSONobj = $RawJSON | ConvertFrom-Json | Select-Object * -ExcludeProperty ID, GUID, *time*
92-
Remove-EmptyArrays -Object $JSONobj
92+
Remove-EmptyArrays $JSONobj
9393
#Remove context as it does not belong in the payload.
9494
try {
9595
if ($JSONobj.grantControls) {

0 commit comments

Comments
 (0)