@@ -64,12 +64,16 @@ function Push-CIPPStandardsList {
6464 } else {
6565 # License valid - check policy timestamps to filter unchanged templates
6666 $TypeMap = @ {
67- Device = ' deviceManagement/deviceConfigurations'
68- Catalog = ' deviceManagement/configurationPolicies'
69- Admin = ' deviceManagement/groupPolicyConfigurations'
70- deviceCompliancePolicies = ' deviceManagement/deviceCompliancePolicies'
71- AppProtection_Android = ' deviceAppManagement/androidManagedAppProtections'
72- AppProtection_iOS = ' deviceAppManagement/iosManagedAppProtections'
67+ Device = ' deviceManagement/deviceConfigurations'
68+ Catalog = ' deviceManagement/configurationPolicies'
69+ Admin = ' deviceManagement/groupPolicyConfigurations'
70+ deviceCompliancePolicies = ' deviceManagement/deviceCompliancePolicies'
71+ AppProtection_Android = ' deviceAppManagement/androidManagedAppProtections'
72+ AppProtection_iOS = ' deviceAppManagement/iosManagedAppProtections'
73+ windowsDriverUpdateProfiles = ' deviceManagement/windowsDriverUpdateProfiles'
74+ windowsFeatureUpdateProfiles = ' deviceManagement/windowsFeatureUpdateProfiles'
75+ windowsQualityUpdatePolicies = ' deviceManagement/windowsQualityUpdatePolicies'
76+ windowsQualityUpdateProfiles = ' deviceManagement/windowsQualityUpdateProfiles'
7377 }
7478
7579 $BulkRequests = $TypeMap.GetEnumerator () | ForEach-Object {
@@ -86,8 +90,9 @@ function Push-CIPPStandardsList {
8690 $PolicyTimestamps = @ {}
8791
8892 foreach ($Result in $BulkResults ) {
89- $GraphTime = $Result.body.value [0 ].lastModifiedDateTime
90- $GraphId = $Result.body.value [0 ].id
93+ $FirstPolicy = if ($Result.body.value ) { $Result.body.value [0 ] } else { $null }
94+ $GraphTime = $FirstPolicy.lastModifiedDateTime
95+ $GraphId = $FirstPolicy.id
9196 $GraphCount = ($Result.body.value | Measure-Object ).Count
9297 $Cached = Get-CIPPAzDataTableEntity @TrackingTable - Filter " PartitionKey eq '$TenantFilter ' and RowKey eq '$ ( $Result.id ) '"
9398
@@ -117,8 +122,24 @@ function Push-CIPPStandardsList {
117122 LatestPolicyId = $GraphId
118123 PolicyCount = $GraphCount
119124 } - Force | Out-Null
125+ } elseif ($Cached -and $Cached.PolicyCount -ne $null ) {
126+ # No timestamp available - fall back to count-based detection
127+ $Changed = $CountChanged -or $IdChanged
128+ Add-CIPPAzDataTableEntity @TrackingTable - Entity @ {
129+ PartitionKey = $TenantFilter
130+ RowKey = $Result.id
131+ LatestPolicyId = $GraphId
132+ PolicyCount = $GraphCount
133+ } - Force | Out-Null
120134 } else {
135+ # No timestamp and no prior cache entry - treat as changed and seed the cache
121136 $Changed = $true
137+ Add-CIPPAzDataTableEntity @TrackingTable - Entity @ {
138+ PartitionKey = $TenantFilter
139+ RowKey = $Result.id
140+ LatestPolicyId = $GraphId
141+ PolicyCount = $GraphCount
142+ } - Force | Out-Null
122143 }
123144
124145 $PolicyTimestamps [$Result.id ] = $Changed
@@ -160,7 +181,7 @@ function Push-CIPPStandardsList {
160181 }
161182
162183 # Check StandardTemplate changes
163- $StandardTemplate = Get-CIPPAzDataTableEntity @StandardTemplateTable - Filter " PartitionKey eq 'StandardsTemplateV2' and RowKey eq '$ ( $Template.TemplateId ) '"
184+ $StandardTemplate = Get-CIPPAzDataTableEntity @TemplateTable - Filter " PartitionKey eq 'StandardsTemplateV2' and RowKey eq '$ ( $Template.TemplateId ) '"
164185 $StandardTemplateChanged = $false
165186
166187 if ($StandardTemplate ) {
@@ -182,7 +203,7 @@ function Push-CIPPStandardsList {
182203 } - Force | Out-Null
183204 }
184205
185- # Remove or downgrade based on change state and compliance
206+ # Remove cosed onmpliance
186207 if (-not $PolicyChanged -and -not $StandardTemplateChanged ) {
187208 $AlignmentKey = " standards.IntuneTemplate.$ ( $Template.Settings.TemplateList.value ) "
188209 $IsDeployed = $IntuneComplianceLookup.ContainsKey ($AlignmentKey )
@@ -192,15 +213,6 @@ function Push-CIPPStandardsList {
192213 # Policy unchanged and compliant - no action needed
193214 Write-Host " NO INTUNE CHANGE: Filtering out $Key for $TenantFilter (compliant)"
194215 [void ]$ComputedStandards.Remove ($Key )
195- } elseif ($IsDeployed ) {
196- # Policy deployed but drifted, and nothing changed - report only, don't force remediate
197- Write-Host " COMPLIANCE DRIFT: Downgrading $Key to Report mode for $TenantFilter (deployed, not compliant, no changes)"
198- $ComputedStandards [$Key ].Settings | Add-Member - NotePropertyName ' remediate' - NotePropertyValue $false - Force
199- $ComputedStandards [$Key ].Settings | Add-Member - NotePropertyName ' report' - NotePropertyValue $true - Force
200- } else {
201- # No alignment data yet - policy not yet deployed, skip (will run on next cycle with changes)
202- Write-Host " NO INTUNE CHANGE: Filtering out $Key for $TenantFilter (not yet deployed, no changes)"
203- [void ]$ComputedStandards.Remove ($Key )
204216 }
205217 }
206218 }
@@ -237,27 +249,28 @@ function Push-CIPPStandardsList {
237249 Write-Information " Updating CIPPDB cache for Conditional Access policies for $TenantFilter "
238250 Set-CIPPDBCacheConditionalAccessPolicies - TenantFilter $TenantFilter
239251 } catch {
240- Write-Warning " Failed to update CA cache for $TenantFilter : $ ( $_.Exception.Message ) "
252+ Write-Warning " Failed to update CA cache for $TenantFilter : $ ( $_.Exception.Message ) '
241253 }
242254 }
243255 }
244256
245- Write-Host " Returning $ ( $ComputedStandards.Count ) standards for tenant $TenantFilter after filtering."
246- # Return filtered standards
247- $FilteredStandards = $ComputedStandards.Values | ForEach-Object {
248- [PSCustomObject ]@ {
249- Tenant = $_.Tenant
250- Standard = $_.Standard
251- Settings = $_.Settings
252- TemplateId = $_.TemplateId
253- FunctionName = ' CIPPStandard'
254- }
255- }
256- Write-Host " Sending back $ ( $FilteredStandards.Count ) standards: $ ( $FilteredStandards | ConvertTo-Json - Depth 5 - Compress) "
257- return $FilteredStandards
257+ Write-Host ' Returning $ ( $ComputedStandards.Count ) standards for tenant $TenantFilter after filtering."
258+ # Return filtered standards
259+ $FilteredStandards = $ComputedStandards.Values | ForEach-Object {
260+ [PSCustomObject ]@ {
261+ Tenant = $_.Tenant
262+ Standard = $_.Standard
263+ Settings = $_.Settings
264+ TemplateId = $_.TemplateId
265+ FunctionName = ' CIPPStandard'
266+ }
267+ }
268+ Write-Host " Sending back $ ( $FilteredStandards.Count ) standards: $ ( $FilteredStandards | ConvertTo-Json - Depth 5 - Compress) "
269+ return @ ( $FilteredStandards )
258270
259- } catch {
260- Write-Warning " Error listing standards for $TenantFilter : $ ( $_.Exception.Message ) "
271+ } catch {
272+ Write-Warning " Error listing standards for $TenantFilter : $ ( $_.Exception.Message ) '
261273 return @()
262274 }
263275}
276+ '
0 commit comments