Skip to content

Commit 6ea35ff

Browse files
committed
Add TemplateId support to standards compare functions
Updated Invoke-ListStandardsCompare and Set-CIPPStandardsCompareField to handle TemplateId filtering and storage. Standards can now be filtered by TemplateId in queries and TemplateId is included in stored entities for improved traceability.
1 parent af75f3d commit 6ea35ff

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,19 @@ function Invoke-ListStandardsCompare {
1111

1212
$Table = Get-CIPPTable -TableName 'CippStandardsReports'
1313
$TenantFilter = $Request.Query.tenantFilter
14+
$TemplateFilter = $Request.Query.templateId
15+
16+
$Filters = [system.collections.generic.list[string]]::new()
1417
if ($TenantFilter) {
15-
$Table.Filter = "PartitionKey eq '{0}'" -f $TenantFilter
18+
$Filters.Add("PartitionKey eq '{0}'" -f $TenantFilter)
19+
}
20+
if ($TemplateFilter) {
21+
$Filters.Add("TemplateId eq '{0}'" -f $TemplateFilter)
1622
}
23+
$Filter = $Filters -join ' and '
1724

1825
$Tenants = Get-Tenants -IncludeErrors
19-
$Standards = Get-CIPPAzDataTableEntity @Table | Where-Object { $_.PartitionKey -in $Tenants.defaultDomainName }
20-
21-
#in the results we have objects starting with "standards." All these have to be converted from JSON. Do not do this is its a boolean
22-
<#$Results | ForEach-Object {
23-
$Object = $_
24-
$Object.PSObject.Properties | ForEach-Object {
25-
if ($_.Name -like 'standards_*') {
26-
if ($_.Value -is [System.Boolean]) {
27-
$_.Value = [bool]$_.Value
28-
} elseif ($_.Value -like '*{*') {
29-
$_.Value = ConvertFrom-Json -InputObject $_.Value -ErrorAction SilentlyContinue
30-
} else {
31-
$_.Value = [string]$_.Value
32-
}
33-
34-
$Key = $_.Name.replace('standards_', 'standards.')
35-
$Key = $Key.replace('IntuneTemplate_', 'IntuneTemplate.')
36-
$Key = $Key -replace '__', '-'
37-
38-
$object | Add-Member -MemberType NoteProperty -Name $Key -Value $_.Value -Force
39-
$object.PSObject.Properties.Remove($_.Name)
40-
}
41-
}
42-
}#>
26+
$Standards = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object { $_.PartitionKey -in $Tenants.defaultDomainName }
4327

4428
$TenantStandards = @{}
4529
$Results = [System.Collections.Generic.List[object]]::new()
@@ -75,6 +59,7 @@ function Invoke-ListStandardsCompare {
7559
$TenantStandards[$Tenant][$FieldName] = @{
7660
Value = $FieldValue
7761
LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
62+
TemplateId = $Standard.TemplateId
7863
}
7964
}
8065

Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ function Set-CIPPStandardsCompareField {
2323
try {
2424
if ($Existing) {
2525
$Existing.Value = $FieldValue
26+
$Existing | Add-Member -NotePropertyName TemplateId -NotePropertyValue $script:StandardInfo.StandardTemplateId -Force
2627
Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force
2728
} else {
2829
$Result = [PSCustomObject]@{
2930
PartitionKey = [string]$TenantName.defaultDomainName
3031
RowKey = [string]$FieldName
3132
Value = $FieldValue
33+
TemplateId = $script:StandardInfo.StandardTemplateId
3234
}
3335
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
3436
}

0 commit comments

Comments
 (0)