|
1 | 1 | function Set-CIPPStandardsCompareField { |
| 2 | + [CmdletBinding(SupportsShouldProcess = $true)] |
2 | 3 | param ( |
3 | 4 | $FieldName, |
4 | 5 | $FieldValue, |
5 | 6 | $TenantFilter |
6 | 7 | ) |
7 | 8 | $Table = Get-CippTable -tablename 'CippStandardsReports' |
8 | | - $TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant |
9 | | - |
10 | | - # Sanitize invalid c#/xml characters for Azure Tables |
11 | | - $FieldName = $FieldName.replace('standards.', 'standards_') |
12 | | - $FieldName = $FieldName.replace('IntuneTemplate.', 'IntuneTemplate_') |
13 | | - $FieldName = $FieldName -replace '-', '__' |
| 9 | + $TenantName = Get-Tenants -TenantFilter $TenantFilter |
14 | 10 |
|
15 | 11 | if ($FieldValue -is [System.Boolean]) { |
16 | | - $fieldValue = [bool]$FieldValue |
| 12 | + $FieldValue = [bool]$FieldValue |
17 | 13 | } elseif ($FieldValue -is [string]) { |
18 | 14 | $FieldValue = [string]$FieldValue |
19 | 15 | } else { |
20 | 16 | $FieldValue = ConvertTo-Json -Compress -InputObject @($FieldValue) -Depth 10 | Out-String |
21 | 17 | $FieldValue = [string]$FieldValue |
22 | 18 | } |
23 | 19 |
|
24 | | - $Existing = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'StandardReport' and RowKey eq '$($TenantName.defaultDomainName)'" |
25 | | - try { |
26 | | - if ($Existing) { |
27 | | - $Existing = $Existing | Select-Object * -ExcludeProperty ETag, TimeStamp | ConvertTo-Json -Depth 10 -Compress | ConvertFrom-Json -AsHashtable |
28 | | - $Existing[$FieldName] = $FieldValue |
29 | | - $Existing['LastRefresh'] = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z') |
30 | | - $Existing = [PSCustomObject]$Existing |
| 20 | + $Existing = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($TenantName.defaultDomainName)' and RowKey eq '$($FieldName)'" |
31 | 21 |
|
32 | | - Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force |
33 | | - } else { |
34 | | - $Result = @{ |
35 | | - tenantFilter = "$($TenantName.defaultDomainName)" |
36 | | - GUID = "$($TenantName.customerId)" |
37 | | - RowKey = "$($TenantName.defaultDomainName)" |
38 | | - PartitionKey = 'StandardReport' |
39 | | - LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z') |
| 22 | + if ($PSCmdlet.ShouldProcess('CIPP Standards Compare', "Set field '$FieldName' to '$FieldValue' for tenant '$($TenantName.defaultDomainName)'")) { |
| 23 | + try { |
| 24 | + if ($Existing) { |
| 25 | + $Existing.Value = $FieldValue |
| 26 | + Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force |
| 27 | + } else { |
| 28 | + $Result = [PSCustomObject]@{ |
| 29 | + PartitionKey = [string]$TenantName.defaultDomainName |
| 30 | + RowKey = [string]$FieldName |
| 31 | + Value = $FieldValue |
| 32 | + } |
| 33 | + Add-CIPPAzDataTableEntity @Table -Entity $Result -Force |
40 | 34 | } |
41 | | - $Result[$FieldName] = $FieldValue |
42 | | - Add-CIPPAzDataTableEntity @Table -Entity $Result -Force |
43 | | - |
| 35 | + Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue" |
| 36 | + } catch { |
| 37 | + Write-Warning "Failed to add $FieldName to StandardCompare for $Tenant. content is $FieldValue - $($_.Exception.Message)" |
44 | 38 | } |
45 | | - Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue" |
46 | | - } catch { |
47 | | - Write-Warning "Failed to add $FieldName to StandardCompare for $Tenant. content is $FieldValue - $($_.Exception.Message)" |
48 | 39 | } |
49 | 40 | } |
0 commit comments