@@ -18,24 +18,28 @@ function Set-CIPPStandardsCompareField {
1818 }
1919
2020 $Existing = Get-CIPPAzDataTableEntity @Table - Filter " PartitionKey eq 'StandardReport' and RowKey eq '$ ( $TenantName.defaultDomainName ) '"
21- if ($Existing ) {
22- $Existing = $Existing | Select-Object * - ExcludeProperty ETag, TimeStamp | ConvertTo-Json - Depth 10 - Compress | ConvertFrom-Json - AsHashtable
23- $Existing [$FieldName ] = $FieldValue
24- $Existing [' LastRefresh' ] = [string ]$ (Get-Date (Get-Date ).ToUniversalTime() - UFormat ' +%Y-%m-%dT%H:%M:%S.000Z' )
25- $Existing = [PSCustomObject ]$Existing
21+ try {
22+ if ($Existing ) {
23+ $Existing = $Existing | Select-Object * - ExcludeProperty ETag, TimeStamp | ConvertTo-Json - Depth 10 - Compress | ConvertFrom-Json - AsHashtable
24+ $Existing [$FieldName ] = $FieldValue
25+ $Existing [' LastRefresh' ] = [string ]$ (Get-Date (Get-Date ).ToUniversalTime() - UFormat ' +%Y-%m-%dT%H:%M:%S.000Z' )
26+ $Existing = [PSCustomObject ]$Existing
2627
27- Add-CIPPAzDataTableEntity @Table - Entity $Existing - Force
28- } else {
29- $Result = @ {
30- tenantFilter = " $ ( $TenantName.defaultDomainName ) "
31- GUID = " $ ( $TenantName.customerId ) "
32- RowKey = " $ ( $TenantName.defaultDomainName ) "
33- PartitionKey = ' StandardReport'
34- LastRefresh = [string ]$ (Get-Date (Get-Date ).ToUniversalTime() - UFormat ' +%Y-%m-%dT%H:%M:%S.000Z' )
35- }
36- $Result [$FieldName ] = $FieldValue
37- Add-CIPPAzDataTableEntity @Table - Entity $Result - Force
28+ Add-CIPPAzDataTableEntity @Table - Entity $Existing - Force
29+ } else {
30+ $Result = @ {
31+ tenantFilter = " $ ( $TenantName.defaultDomainName ) "
32+ GUID = " $ ( $TenantName.customerId ) "
33+ RowKey = " $ ( $TenantName.defaultDomainName ) "
34+ PartitionKey = ' StandardReport'
35+ LastRefresh = [string ]$ (Get-Date (Get-Date ).ToUniversalTime() - UFormat ' +%Y-%m-%dT%H:%M:%S.000Z' )
36+ }
37+ $Result [$FieldName ] = $FieldValue
38+ Add-CIPPAzDataTableEntity @Table - Entity $Result - Force
3839
40+ }
41+ Write-Information " Adding $FieldName to StandardCompare for $Tenant . content is $FieldValue "
42+ } catch {
43+ Write-Warning " Failed to add $FieldName to StandardCompare for $Tenant . content is $FieldValue . The error was: $ ( $_.Exception.Message ) "
3944 }
40- Write-Information " Adding $FieldName to StandardCompare for $Tenant . content is $FieldValue "
4145}
0 commit comments