Skip to content

Commit 67e9fec

Browse files
authored
Merge pull request #198 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 0bdab93 + 87fadf5 commit 67e9fec

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

Modules/CIPPCore/Public/Add-CIPPAzDataTableEntity.ps1

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,32 @@ function Add-CIPPAzDataTableEntity {
2323
$Parameters.OperationType = $OperationType
2424
}
2525

26-
$MaxRowSize = 500000 - 100 # Maximum size of an entity
27-
$MaxSize = 30kb # Maximum size of a property value
26+
$MaxRowSize = 500000 - 100
27+
$MaxSize = 30kb
2828

2929
foreach ($SingleEnt in @($Entity)) {
3030
try {
3131
if ($null -eq $SingleEnt.PartitionKey -or $null -eq $SingleEnt.RowKey) {
3232
throw 'PartitionKey or RowKey is null'
3333
}
34+
3435
Add-AzDataTableEntity @Parameters -Entity $SingleEnt -ErrorAction Stop
36+
3537
} catch [System.Exception] {
36-
if ($_.Exception.ErrorCode -eq 'PropertyValueTooLarge' -or $_.Exception.ErrorCode -eq 'EntityTooLarge' -or $_.Exception.ErrorCode -eq 'RequestBodyTooLarge') {
38+
if ($_.Exception.ErrorCode -in @('PropertyValueTooLarge', 'EntityTooLarge', 'RequestBodyTooLarge')) {
3739
try {
3840
Write-Host 'Entity is too large. Splitting entity into multiple parts.'
39-
#Write-Information ($SingleEnt | ConvertTo-Json)
41+
4042
$largePropertyNames = [System.Collections.Generic.List[string]]::new()
4143
$entitySize = 0
4244

43-
# Convert $SingleEnt to hashtable if it is a PSObject
4445
if ($SingleEnt -is [System.Management.Automation.PSCustomObject]) {
4546
$SingleEnt = $SingleEnt | ConvertTo-Json -Depth 100 -Compress | ConvertFrom-Json -AsHashtable
4647
}
4748

4849
foreach ($key in $SingleEnt.Keys) {
4950
$propertySize = [System.Text.Encoding]::UTF8.GetByteCount($SingleEnt[$key].ToString())
50-
$entitySize = $entitySize + $propertySize
51+
$entitySize += $propertySize
5152
if ($propertySize -gt $MaxSize) {
5253
$largePropertyNames.Add($key)
5354
}
@@ -63,7 +64,7 @@ function Add-CIPPAzDataTableEntity {
6364
$start = $i * $MaxSize
6465
$splitData.Add($dataString.Substring($start, [Math]::Min($MaxSize, $dataString.Length - $start))) > $null
6566
}
66-
$splitDataCount = ($splitData | Measure-Object).Count
67+
$splitDataCount = $splitData.Count
6768
$splitPropertyNames = [System.Collections.Generic.List[object]]::new()
6869
for ($i = 0; $i -lt $splitDataCount; $i++) {
6970
$splitPropertyNames.Add("${largePropertyName}_Part$i")
@@ -80,11 +81,9 @@ function Add-CIPPAzDataTableEntity {
8081
$SingleEnt[$splitPropertyNames[$i]] = $splitData[$i]
8182
}
8283
}
83-
8484
$SingleEnt['SplitOverProps'] = ($splitInfoList | ConvertTo-Json -Compress).ToString()
8585
}
8686

87-
# Check if the entity is still too large
8887
$entitySize = [System.Text.Encoding]::UTF8.GetByteCount($($SingleEnt | ConvertTo-Json -Compress))
8988
if ($entitySize -gt $MaxRowSize) {
9089
$rows = [System.Collections.Generic.List[object]]::new()
@@ -96,11 +95,7 @@ function Add-CIPPAzDataTableEntity {
9695
Write-Information "Entity size is $entitySize. Splitting entity into multiple parts."
9796
$newEntity = @{}
9897
$newEntity['PartitionKey'] = $originalPartitionKey
99-
if ($entityIndex -eq 0) {
100-
$newEntity['RowKey'] = $originalRowKey
101-
} else {
102-
$newEntity['RowKey'] = "$($originalRowKey)-part$entityIndex"
103-
}
98+
$newEntity['RowKey'] = if ($entityIndex -eq 0) { $originalRowKey } else { "$($originalRowKey)-part$entityIndex" }
10499
$newEntity['OriginalEntityId'] = $originalRowKey
105100
$newEntity['PartIndex'] = $entityIndex
106101
$entityIndex++
@@ -142,12 +137,11 @@ function Add-CIPPAzDataTableEntity {
142137
$entitySize = [System.Text.Encoding]::UTF8.GetByteCount($($SingleEnt | ConvertTo-Json -Compress))
143138
}
144139

145-
if (($SingleEnt | Measure-Object).Count -gt 0) {
140+
if ($SingleEnt.Count -gt 0) {
146141
$SingleEnt['RowKey'] = "$($originalRowKey)-part$entityIndex"
147142
$SingleEnt['OriginalEntityId'] = $originalRowKey
148143
$SingleEnt['PartIndex'] = $entityIndex
149144
$SingleEnt['PartitionKey'] = $originalPartitionKey
150-
151145
$rows.Add($SingleEnt)
152146
}
153147

@@ -156,14 +150,28 @@ function Add-CIPPAzDataTableEntity {
156150
$NewRow = ([PSCustomObject]$row) | Select-Object * -ExcludeProperty Timestamp
157151
Add-AzDataTableEntity @Parameters -Entity $NewRow
158152
}
153+
159154
} else {
160155
$NewEnt = ([PSCustomObject]$SingleEnt) | Select-Object * -ExcludeProperty Timestamp
161156
Add-AzDataTableEntity @Parameters -Entity $NewEnt
157+
if ($NewEnt.PSObject.Properties['OriginalEntityId'] -eq $null -and $NewEnt.PSObject.Properties['PartIndex'] -eq $null) {
158+
$partIndex = 1
159+
while ($true) {
160+
$partRowKey = "$($NewEnt.RowKey)-part$partIndex"
161+
try {
162+
Remove-AzDataTableEntity -Context $Context -PartitionKey $NewEnt.PartitionKey -RowKey $partRowKey -ErrorAction Stop
163+
Write-Information "Deleted obsolete part: $partRowKey"
164+
$partIndex++
165+
} catch {
166+
break
167+
}
168+
}
169+
}
162170
}
163171

164172
} catch {
165173
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
166-
Write-Warning ('AzBobbyTables Error')
174+
Write-Warning 'AzBobbyTables Error'
167175
Write-Information ($SingleEnt | ConvertTo-Json)
168176
throw "Error processing entity: $ErrorMessage Linenumber: $($_.InvocationInfo.ScriptLineNumber)"
169177
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-SchedulerCIPPNotifications.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Push-SchedulerCIPPNotifications {
4646
Send-CIPPAlert -Type 'email' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'
4747
}
4848
} else {
49-
$Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | ConvertTo-Html -frag)
49+
$Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity)
5050
$Subject = "CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
5151
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'table'
5252
Send-CIPPAlert -Type 'email' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'
@@ -109,7 +109,7 @@ function Push-SchedulerCIPPNotifications {
109109
if ($config.sendtoIntegration) {
110110
try {
111111
foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
112-
$Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant | ConvertTo-Html -frag)
112+
$Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant)
113113
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'table'
114114
$Title = "$tenant CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
115115
Send-CIPPAlert -Type 'psa' -Title $Title -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardPWcompanionAppAllowedState.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function Invoke-CIPPStandardPWcompanionAppAllowedState {
3636

3737

3838
# Get state value using null-coalescing operator
39-
$state = $Settings.state.value ?? $Settings.state
39+
$state = $Settings.state.value ? $Settings.state.value : $settings.state
40+
$authState = if ($authenticatorFeaturesState.featureSettings.companionAppAllowedState.state -eq $state) { $true } else { $false }
4041

4142
# Input validation
4243
if (([string]::IsNullOrWhiteSpace($state) -or $state -eq 'Select a value') -and ($Settings.remediate -eq $true -or $Settings.alert -eq $true)) {

0 commit comments

Comments
 (0)