Skip to content

Commit 6ad08e8

Browse files
updates to cippstandardscomparefield for new planning.
1 parent fdb75e7 commit 6ad08e8

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

Modules/CIPPCore/Public/Functions/Test-CIPPStandardLicense.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Test-CIPPStandardLicense {
4646
if ($Capabilities.Count -le 0) {
4747
if (!$SkipLog.IsPresent) {
4848
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Tenant does not have the required capability to run standard $StandardName`: The tenant needs one of the following service plans: $($RequiredCapabilities -join ',')" -sev Info
49-
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: This tenant is not licensed for the following capabilities: $($RequiredCapabilities -join ',')" -Tenant $TenantFilter
49+
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -LicenseAvailable $false -FieldValue "License Missing: This tenant is not licensed for the following capabilities: $($RequiredCapabilities -join ',')" -Tenant $TenantFilter
5050
Write-Verbose "Tenant does not have the required capability to run standard $StandardName - $($RequiredCapabilities -join ','). Exiting"
5151
}
5252
return $false

Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ function Set-CIPPStandardsCompareField {
22
[CmdletBinding(SupportsShouldProcess = $true)]
33
param (
44
$FieldName,
5-
$FieldValue,
5+
$FieldValue, #FieldValue is here for backward compatibility.
6+
$CurrentValue, #The latest actual value in raw json
7+
$ExpectedValue, #The expected value - e.g. the settings object from our standard
68
$TenantFilter,
79
[Parameter()]
10+
[bool]$LicenseAvailable = $true,
11+
[Parameter()]
812
[array]$BulkFields
913
)
1014
$Table = Get-CippTable -tablename 'CippStandardsReports'
1115
$TenantName = Get-Tenants -TenantFilter $TenantFilter
1216

13-
# Helper function to normalize field values
17+
# Helper function to normalize field values. This can go in a couple of releases tbh.
1418
function ConvertTo-NormalizedFieldValue {
1519
param($Value)
1620
if ($Value -is [System.Boolean]) {
@@ -34,20 +38,26 @@ function Set-CIPPStandardsCompareField {
3438

3539
# Build array of entities to insert/update
3640
$EntitiesToProcess = [System.Collections.Generic.List[object]]::new()
37-
41+
3842
foreach ($Field in $BulkFields) {
3943
$NormalizedValue = ConvertTo-NormalizedFieldValue -Value $Field.FieldValue
40-
44+
4145
if ($ExistingHash.ContainsKey($Field.FieldName)) {
4246
$Entity = $ExistingHash[$Field.FieldName]
4347
$Entity.Value = $NormalizedValue
4448
$Entity | Add-Member -NotePropertyName TemplateId -NotePropertyValue ([string]$script:CippStandardInfoStorage.Value.StandardTemplateId) -Force
49+
$Entity | Add-Member -NotePropertyName LicenseAvailable -NotePropertyValue ([bool]$Field.LicenseAvailable) -Force
50+
$Entity | Add-Member -NotePropertyName CurrentValue -NotePropertyValue ([string]$Field.CurrentValue) -Force
51+
$Entity | Add-Member -NotePropertyName ExpectedValue -NotePropertyValue ([string]$Field.ExpectedValue) -Force
4552
} else {
4653
$Entity = [PSCustomObject]@{
47-
PartitionKey = [string]$TenantName.defaultDomainName
48-
RowKey = [string]$Field.FieldName
49-
Value = $NormalizedValue
50-
TemplateId = [string]$script:CippStandardInfoStorage.Value.StandardTemplateId
54+
PartitionKey = [string]$TenantName.defaultDomainName
55+
RowKey = [string]$Field.FieldName
56+
Value = $NormalizedValue
57+
TemplateId = [string]$script:CippStandardInfoStorage.Value.StandardTemplateId
58+
LicenseAvailable = [bool]$Field.LicenseAvailable
59+
CurrentValue = [string]$Field.CurrentValue
60+
ExpectedValue = [string]$Field.ExpectedValue
5161
}
5262
}
5363
$EntitiesToProcess.Add($Entity)
@@ -72,13 +82,19 @@ function Set-CIPPStandardsCompareField {
7282
if ($Existing) {
7383
$Existing.Value = $NormalizedValue
7484
$Existing | Add-Member -NotePropertyName TemplateId -NotePropertyValue ([string]$script:CippStandardInfoStorage.Value.StandardTemplateId) -Force
85+
$Existing | Add-Member -NotePropertyName LicenseAvailable -NotePropertyValue ([bool]$LicenseAvailable) -Force
86+
$Existing | Add-Member -NotePropertyName CurrentValue -NotePropertyValue ([string]$CurrentValue) -Force
87+
$Existing | Add-Member -NotePropertyName ExpectedValue -NotePropertyValue ([string]$ExpectedValue) -Force
7588
Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force
7689
} else {
7790
$Result = [PSCustomObject]@{
78-
PartitionKey = [string]$TenantName.defaultDomainName
79-
RowKey = [string]$FieldName
80-
Value = $NormalizedValue
81-
TemplateId = [string]$script:CippStandardInfoStorage.Value.StandardTemplateId
91+
PartitionKey = [string]$TenantName.defaultDomainName
92+
RowKey = [string]$FieldName
93+
Value = $NormalizedValue
94+
TemplateId = [string]$script:CippStandardInfoStorage.Value.StandardTemplateId
95+
LicenseAvailable = [bool]$LicenseAvailable
96+
CurrentValue = [string]$CurrentValue
97+
ExpectedValue = [string]$ExpectedValue
8298
}
8399
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
84100
}

0 commit comments

Comments
 (0)