Skip to content

Commit 0dc03d1

Browse files
fixes issue with shrinking tables
1 parent 8a401a5 commit 0dc03d1

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,43 @@ function Get-CIPPAzDataTableEntity {
1212

1313
$Results = Get-AzDataTableEntity @PSBoundParameters
1414
$mergedResults = @{}
15+
$rootEntities = @{} # Keyed by "$PartitionKey|$RowKey"
1516

16-
# First pass: Collect all parts and complete entities
1717
foreach ($entity in $Results) {
18-
if ($entity.OriginalEntityId) {
19-
$entityId = $entity.OriginalEntityId
20-
$partitionKey = $entity.PartitionKey
21-
if (-not $mergedResults.ContainsKey($partitionKey)) {
22-
$mergedResults[$partitionKey] = @{}
23-
}
24-
if (-not $mergedResults[$partitionKey].ContainsKey($entityId)) {
25-
$mergedResults[$partitionKey][$entityId] = @{
26-
Parts = [System.Collections.Generic.List[object]]::new()
27-
}
28-
}
29-
$mergedResults[$partitionKey][$entityId]['Parts'].Add($entity)
30-
} else {
31-
$partitionKey = $entity.PartitionKey
32-
if (-not $mergedResults.ContainsKey($partitionKey)) {
33-
$mergedResults[$partitionKey] = @{}
34-
}
35-
$mergedResults[$partitionKey][$entity.RowKey] = @{
18+
$partitionKey = $entity.PartitionKey
19+
$rowKey = $entity.RowKey
20+
$hasOriginalId = $entity.PSObject.Properties.Match('OriginalEntityId') -and $entity.OriginalEntityId
21+
22+
if (-not $mergedResults.ContainsKey($partitionKey)) {
23+
$mergedResults[$partitionKey] = @{}
24+
}
25+
26+
if (-not $hasOriginalId) {
27+
# It's a standalone root row
28+
$rootEntities["$partitionKey|$rowKey"] = $true
29+
$mergedResults[$partitionKey][$rowKey] = @{
3630
Entity = $entity
3731
Parts = [System.Collections.Generic.List[object]]::new()
3832
}
33+
continue
34+
}
35+
36+
# It's a part of something else
37+
$entityId = $entity.OriginalEntityId
38+
39+
# Check if this entity's target has a "real" base
40+
if ($rootEntities.ContainsKey("$partitionKey|$entityId")) {
41+
# Root row exists → skip merging this part
42+
continue
43+
}
44+
45+
# Merge it as a part
46+
if (-not $mergedResults[$partitionKey].ContainsKey($entityId)) {
47+
$mergedResults[$partitionKey][$entityId] = @{
48+
Parts = [System.Collections.Generic.List[object]]::new()
49+
}
3950
}
51+
$mergedResults[$partitionKey][$entityId]['Parts'].Add($entity)
4052
}
4153

4254
$finalResults = [System.Collections.Generic.List[object]]::new()

0 commit comments

Comments
 (0)