Skip to content

Commit 9b587ca

Browse files
committed
debug logging
1 parent 225e06b commit 9b587ca

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandardsList.ps1

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ function Push-CIPPStandardsList {
143143
}
144144

145145
$PolicyTimestamps[$Result.id] = $Changed
146+
Write-Host "POLICY TYPE CHANGE CHECK: $($Result.id) -> Changed=$Changed (GraphCount=$GraphCount, CachedCount=$($Cached.PolicyCount), IdChanged=$IdChanged)"
146147
}
147148

148149
# Filter unchanged templates
149150
$TemplateTable = Get-CippTable -tablename 'templates'
150151
$IntuneKeys = @($ComputedStandards.Keys | Where-Object { $_ -like '*IntuneTemplate*' })
152+
Write-Host "INTUNE FILTER: Processing $($IntuneKeys.Count) IntuneTemplate standards for $TenantFilter"
151153

152154
# Build compliance lookup - keyed by "standards.IntuneTemplate.<templateValue>"
153155
$IntuneComplianceLookup = @{}
@@ -163,22 +165,30 @@ function Push-CIPPStandardsList {
163165
} catch {
164166
Write-Warning "Failed to get tenant alignment data for $TenantFilter : $($_.Exception.Message)"
165167
}
168+
Write-Host "COMPLIANCE LOOKUP: Found $($IntuneComplianceLookup.Count) IntuneTemplate entries in alignment data"
166169

167170
foreach ($Key in $IntuneKeys) {
168171
$Template = $ComputedStandards[$Key]
169172
$TemplateEntity = Get-CIPPAzDataTableEntity @TemplateTable -Filter "PartitionKey eq 'IntuneTemplate' and RowKey eq '$($Template.Settings.TemplateList.value)'"
170173

171-
if (-not $TemplateEntity) { continue }
174+
if (-not $TemplateEntity) {
175+
Write-Host "SKIP: $Key - no IntuneTemplate entity found for RowKey '$($Template.Settings.TemplateList.value)'"
176+
continue
177+
}
172178

173179
$ParsedTemplate = $TemplateEntity.JSON | ConvertFrom-Json
174-
if (-not $ParsedTemplate.Type) { continue }
180+
if (-not $ParsedTemplate.Type) {
181+
Write-Host "SKIP: $Key - template has no Type property"
182+
continue
183+
}
175184

176185
$PolicyType = $ParsedTemplate.Type
177186
$PolicyChanged = if ($PolicyType -eq 'AppProtection') {
178187
[bool]($PolicyTimestamps['AppProtection_Android'] -or $PolicyTimestamps['AppProtection_iOS'])
179188
} else {
180189
[bool]$PolicyTimestamps[$PolicyType]
181190
}
191+
Write-Host "TEMPLATE CHECK: $Key | PolicyType=$PolicyType | PolicyChanged=$PolicyChanged"
182192

183193
# Check StandardTemplate changes
184194
$StandardTemplate = Get-CIPPAzDataTableEntity @TemplateTable -Filter "PartitionKey eq 'StandardsTemplateV2' and RowKey eq '$($Template.TemplateId)'"
@@ -192,8 +202,10 @@ function Push-CIPPStandardsList {
192202
$CachedStandardTimeUtc = ([DateTimeOffset]$CachedStandardTemplate.CachedTimestamp).UtcDateTime
193203
$TimeDiff = [Math]::Abs(($StandardTimeUtc - $CachedStandardTimeUtc).TotalSeconds)
194204
$StandardTemplateChanged = ($TimeDiff -gt 60)
205+
Write-Host "STDTEMPLATE CHECK: TemplateId=$($Template.TemplateId) | TimeDiff=${TimeDiff}s | Changed=$StandardTemplateChanged"
195206
} else {
196207
$StandardTemplateChanged = $true
208+
Write-Host "STDTEMPLATE CHECK: TemplateId=$($Template.TemplateId) | No cached timestamp - treating as changed"
197209
}
198210

199211
Add-CIPPAzDataTableEntity @TrackingTable -Entity @{
@@ -207,12 +219,17 @@ function Push-CIPPStandardsList {
207219
$AlignmentKey = "standards.IntuneTemplate.$($Template.Settings.TemplateList.value)"
208220
$IsDeployed = $IntuneComplianceLookup.ContainsKey($AlignmentKey)
209221
$IsCompliant = $IsDeployed -and ($IntuneComplianceLookup[$AlignmentKey] -eq $true)
222+
Write-Host "COMPLIANCE CHECK: $AlignmentKey | InLookup=$IsDeployed | Compliant=$IsCompliant | LookupValue=$($IntuneComplianceLookup[$AlignmentKey])"
210223

211224
if ($IsCompliant) {
212225
# Policy unchanged and compliant - no action needed
213226
Write-Host "NO INTUNE CHANGE: Filtering out $Key for $TenantFilter (compliant)"
214227
[void]$ComputedStandards.Remove($Key)
228+
} else {
229+
Write-Host "KEEPING: $Key - not compliant or not in lookup (InLookup=$IsDeployed, Compliant=$IsCompliant)"
215230
}
231+
} else {
232+
Write-Host "KEEPING: $Key - changed (PolicyChanged=$PolicyChanged, StdTemplateChanged=$StandardTemplateChanged)"
216233
}
217234
}
218235
} catch {
@@ -266,10 +283,8 @@ function Push-CIPPStandardsList {
266283
}
267284
Write-Host "Sending back $($FilteredStandards.Count) standards"
268285
return @($FilteredStandards)
269-
270286
} catch {
271287
Write-Warning "Error listing standards for $TenantFilter : $($_.Exception.Message)"
272288
return @()
273289
}
274290
}
275-

0 commit comments

Comments
 (0)