Skip to content

Commit d64fb33

Browse files
authored
Merge pull request #664 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents eaa0e22 + 470c024 commit d64fb33

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,29 @@ function Invoke-ListStandardsCompare {
5353
$FieldValue = [string]$FieldValue
5454
}
5555

56+
# Parse CurrentValue and ExpectedValue from JSON if they are JSON strings
57+
$ParsedCurrentValue = if ($Standard.CurrentValue -and (Test-Json -Json $Standard.CurrentValue -ErrorAction SilentlyContinue)) {
58+
ConvertFrom-Json -InputObject $Standard.CurrentValue -ErrorAction SilentlyContinue
59+
} else {
60+
$Standard.CurrentValue
61+
}
62+
63+
$ParsedExpectedValue = if ($Standard.ExpectedValue -and (Test-Json -Json $Standard.ExpectedValue -ErrorAction SilentlyContinue)) {
64+
ConvertFrom-Json -InputObject $Standard.ExpectedValue -ErrorAction SilentlyContinue
65+
} else {
66+
$Standard.ExpectedValue
67+
}
68+
5669
if (-not $TenantStandards.ContainsKey($Tenant)) {
5770
$TenantStandards[$Tenant] = @{}
5871
}
5972
$TenantStandards[$Tenant][$FieldName] = @{
60-
Value = $FieldValue
61-
LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
62-
TemplateId = $Standard.TemplateId
73+
Value = $FieldValue
74+
LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
75+
TemplateId = $Standard.TemplateId
76+
LicenseAvailable = $Standard.LicenseAvailable
77+
CurrentValue = $ParsedCurrentValue
78+
ExpectedValue = $ParsedExpectedValue
6379
}
6480
}
6581

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ function Get-CIPPTenantAlignment {
9090
$tenantData[$Tenant] = @{}
9191
}
9292
$tenantData[$Tenant][$FieldName] = @{
93-
Value = $FieldValue
94-
LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
93+
Value = $FieldValue
94+
LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
95+
LicenseAvailable = $Standard.LicenseAvailable
96+
CurrentValue = $Standard.CurrentValue
97+
ExpectedValue = $Standard.ExpectedValue
9598
}
9699
}
97100
$TenantStandards = $tenantData
@@ -276,6 +279,9 @@ function Get-CIPPTenantAlignment {
276279
StandardValue = $StandardValueJson
277280
ComplianceStatus = $ComplianceStatus
278281
ReportingDisabled = $IsReportingDisabled
282+
LicenseAvailable = $StandardObject.LicenseAvailable
283+
CurrentValue = $StandardObject.CurrentValue
284+
ExpectedValue = $StandardObject.ExpectedValue
279285
})
280286
} else {
281287
$ComplianceStatus = if ($IsReportingDisabled) {
@@ -290,6 +296,9 @@ function Get-CIPPTenantAlignment {
290296
StandardValue = 'NOT FOUND'
291297
ComplianceStatus = $ComplianceStatus
292298
ReportingDisabled = $IsReportingDisabled
299+
LicenseAvailable = $null
300+
CurrentValue = $null
301+
ExpectedValue = $null
293302
})
294303
}
295304
}

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/Get-CIPPDrift.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ function Get-CIPPDrift {
129129
standardName = $ComparisonItem.StandardName
130130
standardDisplayName = $displayName
131131
standardDescription = $standardDescription
132-
expectedValue = 'Compliant'
133132
receivedValue = $ComparisonItem.StandardValue
134133
state = 'current'
135134
Status = $Status
136135
Reason = $reason
137136
lastChangedByUser = $User
137+
LicenseAvailable = $ComparisonItem.LicenseAvailable
138+
CurrentValue = $ComparisonItem.CurrentValue
139+
ExpectedValue = $ComparisonItem.ExpectedValue
138140
})
139141
}
140142
}
@@ -286,7 +288,7 @@ function Get-CIPPDrift {
286288
standardName = $PolicyKey
287289
standardDisplayName = "Intune - $TenantPolicyName"
288290
expectedValue = 'This policy only exists in the tenant, not in the template.'
289-
receivedValue = $TenantPolicy.Policy
291+
receivedValue = ($TenantPolicy.Policy | ConvertTo-Json -Depth 10 -Compress)
290292
state = 'current'
291293
Status = $Status
292294
Reason = $reason

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
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Invoke-CIPPStandardEXODirectSend {
3838
# Input validation
3939
if ([string]::IsNullOrWhiteSpace($DesiredStateName) -or $DesiredStateName -eq 'Select a value') {
4040
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'EXODirectSend: Invalid state parameter set' -sev Error
41-
Return
41+
return
4242
}
4343

4444
# Get current organization config
@@ -85,8 +85,13 @@ function Invoke-CIPPStandardEXODirectSend {
8585

8686
# Report if needed
8787
if ($Settings.report -eq $true) {
88-
89-
Set-CIPPStandardsCompareField -FieldName 'standards.EXODirectSend' -FieldValue $StateIsCorrect -Tenant $Tenant
88+
$ExpectedState = @{
89+
RejectDirectSend = $DesiredState
90+
} | ConvertTo-Json -Depth 10 -Compress
91+
$CurrentState = @{
92+
RejectDirectSend = $CurrentConfig
93+
} | ConvertTo-Json -Depth 10 -Compress
94+
Set-CIPPStandardsCompareField -FieldName 'standards.EXODirectSend' -CurrentValue $CurrentState -ExpectedValue $ExpectedState -Tenant $Tenant
9095
Add-CIPPBPAField -FieldName 'EXODirectSend' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
9196
}
9297
}

0 commit comments

Comments
 (0)