Skip to content

Commit 084bbee

Browse files
authored
Merge pull request #998 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 53d7cca + 2b093c3 commit 084bbee

14 files changed

Lines changed: 98 additions & 32 deletions

File tree

Modules/CIPPActivityTriggers/Public/Entrypoints/Activity Triggers/Push-ListMailQuarantineAllTenants.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
Write-Host "PowerShell queue trigger function processed work item: $($Tenant.defaultDomainName)"
1212

1313
try {
14-
$quarantineMessages = New-ExoRequest -tenantid $domainName -cmdlet 'Get-QuarantineMessage' -cmdParams @{ 'PageSize' = 1000 } | Select-Object -ExcludeProperty *data.type*
14+
$Page = 1
15+
$PageSize = 1000
16+
$quarantineMessages = [System.Collections.Generic.List[object]]::new()
17+
do {
18+
$Results = New-ExoRequest -tenantid $domainName -cmdlet 'Get-QuarantineMessage' -cmdParams @{ PageSize = $PageSize; Page = $Page } | Select-Object -ExcludeProperty *data.type*
19+
if ($Results) { $quarantineMessages.AddRange(@($Results)) }
20+
$Page++
21+
} while (@($Results).Count -eq $PageSize)
1522
foreach ($message in $quarantineMessages) {
1623
$messageData = @{
1724
QuarantineMessage = [string]($message | ConvertTo-Json -Depth 10 -Compress)

Modules/CIPPActivityTriggers/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandard.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Push-CIPPStandard {
2121
$API = "$($Standard)_$($Item.TemplateId)"
2222
}
2323

24-
$Rerun = Test-CIPPRerun -Type Standard -Tenant $Tenant -API $API
24+
$Rerun = Test-CIPPRerun -Type Standard -Tenant $Tenant -API $API -BaseTime ([int64]$Item.QueuedTime)
2525
if ($Rerun) {
2626
Write-Information 'Detected rerun. Exiting cleanly'
2727
return

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ function Push-CIPPStandardsList {
281281

282282
Write-Host "Returning $($ComputedStandards.Count) standards for tenant $TenantFilter after filtering."
283283
# Return filtered standards
284+
$QueuedTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
284285
$FilteredStandards = $ComputedStandards.Values | ForEach-Object {
285286
[PSCustomObject]@{
286287
Tenant = $_.Tenant
287288
Standard = $_.Standard
288289
Settings = $_.Settings
289290
TemplateId = $_.TemplateId
290291
FunctionName = 'CIPPStandard'
292+
QueuedTime = $QueuedTime
291293
}
292294
}
293295
Write-Host "Sending back $($FilteredStandards.Count) standards"

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ function Get-CIPPTenantAlignment {
8080
$TemplatesByPackage[$t.Package].Add($t)
8181
}
8282
}
83+
$CATagTemplates = Get-CIPPAzDataTableEntity @TemplateTable -Filter "PartitionKey eq 'CATemplate'"
84+
$CATemplatesByPackage = @{}
85+
foreach ($t in $CATagTemplates) {
86+
if ($t.Package) {
87+
if (-not $CATemplatesByPackage.ContainsKey($t.Package)) {
88+
$CATemplatesByPackage[$t.Package] = [System.Collections.Generic.List[object]]::new()
89+
}
90+
$CATemplatesByPackage[$t.Package].Add($t)
91+
}
92+
}
8393
# Build tenant standards data structure
8494
$tenantData = @{}
8595
foreach ($Standard in $Standards) {
@@ -245,7 +255,8 @@ function Get-CIPPTenantAlignment {
245255
Write-Host "Processing CA Tag: $($Tag.value)"
246256
$CAActions = if ($CATemplate.action) { $CATemplate.action } else { @() }
247257
$CAReportingEnabled = ($CAActions | Where-Object { $_.value -and ($_.value.ToLower() -eq 'report' -or $_.value.ToLower() -eq 'remediate') }).Count -gt 0
248-
$TagTemplate = $TagTemplates | Where-Object -Property package -EQ $Tag.value
258+
$TagValue = if ($Tag.value) { $Tag.value } else { $Tag }
259+
$TagTemplate = if ($CATemplatesByPackage.ContainsKey($TagValue)) { $CATemplatesByPackage[$TagValue] } else { @() }
249260
$TagTemplate | ForEach-Object {
250261
$TagStandardId = "standards.ConditionalAccessTemplate.$($_.GUID)"
251262
[PSCustomObject]@{
@@ -438,8 +449,7 @@ function Get-CIPPTenantAlignment {
438449
$DeniedDeviationsCount++
439450
}
440451
}
441-
}
442-
elseif ($item.ComplianceStatus -eq 'License Missing') { $LicenseMissingStandards++ }
452+
} elseif ($item.ComplianceStatus -eq 'License Missing') { $LicenseMissingStandards++ }
443453
if ($item.ReportingDisabled) { $ReportingDisabledStandardsCount++ }
444454
}
445455

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ function Get-CIPPDrift {
6565
# Load CA templates with GUID hashtable
6666
$RawCATemplates = Get-CIPPAzDataTableEntity @IntuneTable -Filter "PartitionKey eq 'CATemplate'"
6767
$CATemplatesByGuid = @{}
68+
# Build a hashtable indexed by Package for O(1) CA tag lookup
69+
$CATemplatesByPackage = @{}
70+
foreach ($t in $RawCATemplates) {
71+
if ($t.Package) {
72+
if (-not $CATemplatesByPackage.ContainsKey($t.Package)) {
73+
$CATemplatesByPackage[$t.Package] = [System.Collections.Generic.List[object]]::new()
74+
}
75+
$CATemplatesByPackage[$t.Package].Add($t)
76+
}
77+
}
6878
$AllCATemplates = foreach ($RawTemplate in $RawCATemplates) {
6979
try {
7080
$data = $RawTemplate.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
@@ -279,9 +289,15 @@ function Get-CIPPDrift {
279289
if ($Template.TemplateList.value) {
280290
$CATemplateIds.Add($Template.TemplateList.value)
281291
}
282-
if ($Template.'TemplateList-Tags'.rawData.templates) {
283-
foreach ($TagTemplate in $Template.'TemplateList-Tags'.rawData.templates) {
284-
$CATemplateIds.Add($TagTemplate.GUID)
292+
if ($Template.'TemplateList-Tags') {
293+
$TagValue = if ($Template.'TemplateList-Tags'.value) { $Template.'TemplateList-Tags'.value } else { $null }
294+
if ($TagValue) {
295+
$ResolvedCATagTemplates = if ($CATemplatesByPackage.ContainsKey($TagValue)) { $CATemplatesByPackage[$TagValue] } else { @() }
296+
foreach ($ResolvedTemplate in $ResolvedCATagTemplates) {
297+
if ($ResolvedTemplate.RowKey -and $ResolvedTemplate.RowKey -notin $CATemplateIds) {
298+
$CATemplateIds.Add($ResolvedTemplate.RowKey)
299+
}
300+
}
285301
}
286302
}
287303
}
@@ -396,12 +412,12 @@ function Get-CIPPDrift {
396412
if (-not $ExistingDriftStates.ContainsKey($Deviation.standardName)) {
397413
$RowKey = $Deviation.standardName -replace '\.', '_'
398414
$NewDriftEntities.Add(@{
399-
PartitionKey = $TenantFilter
400-
RowKey = $RowKey
401-
StandardName = $Deviation.standardName
402-
Status = 'New'
403-
LastModified = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
404-
})
415+
PartitionKey = $TenantFilter
416+
RowKey = $RowKey
417+
StandardName = $Deviation.standardName
418+
Status = 'New'
419+
LastModified = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
420+
})
405421
}
406422
}
407423
if ($NewDriftEntities.Count -gt 0) {

Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Get-CIPPStandards {
4949
$IsArray = $StandardValue -is [System.Collections.IEnumerable] -and -not ($StandardValue -is [string])
5050

5151
if ($IsArray) {
52-
$NewArray = foreach ($Item in $StandardValue) {
52+
$NewArray = @(foreach ($Item in $StandardValue) {
5353
if ($Item.'TemplateList-Tags'.value) {
5454
$HasExpansions = $true
5555
$Table = Get-CippTable -tablename 'templates'
@@ -60,6 +60,7 @@ function Get-CIPPStandards {
6060
}
6161
$Filter = "PartitionKey eq '$PartitionKey'"
6262
$TemplatesList = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object -Property package -EQ $Item.'TemplateList-Tags'.value
63+
Write-Information "Expanding $StandardName tag '$($Item.'TemplateList-Tags'.value)' from partition '$PartitionKey': found $(@($TemplatesList).Count) templates"
6364

6465
foreach ($TemplateItem in $TemplatesList) {
6566
$TemplateJSON = $TemplateItem.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
@@ -77,8 +78,10 @@ function Get-CIPPStandards {
7778
$Item | Add-Member -NotePropertyName TemplateId -NotePropertyValue $Template.GUID -Force
7879
$Item
7980
}
81+
})
82+
if ($NewArray.Count -gt 0) {
83+
$ExpandedStandards[$StandardName] = $NewArray
8084
}
81-
$ExpandedStandards[$StandardName] = $NewArray
8285
} else {
8386
if ($StandardValue.'TemplateList-Tags'.value) {
8487
$HasExpansions = $true
@@ -139,6 +142,7 @@ function Get-CIPPStandards {
139142

140143
foreach ($StandardName in $Standards.PSObject.Properties.Name) {
141144
$Value = $Standards.$StandardName
145+
if ($null -eq $Value) { continue }
142146
$IsArray = $Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])
143147

144148
if ($IsArray) {
@@ -282,6 +286,7 @@ function Get-CIPPStandards {
282286

283287
foreach ($StandardName in $Standards.PSObject.Properties.Name) {
284288
$Value = $Standards.$StandardName
289+
if ($null -eq $Value) { continue }
285290
$IsArray = $Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])
286291

287292
if ($IsArray) {
@@ -351,6 +356,7 @@ function Get-CIPPStandards {
351356

352357
foreach ($StandardName in $Standards.PSObject.Properties.Name) {
353358
$Value = $Standards.$StandardName
359+
if ($null -eq $Value) { continue }
354360
$IsArray = $Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])
355361

356362
if ($IsArray) {
@@ -430,6 +436,7 @@ function Get-CIPPStandards {
430436

431437
foreach ($StandardName in $Standards.PSObject.Properties.Name) {
432438
$Value = $Standards.$StandardName
439+
if ($null -eq $Value) { continue }
433440
$IsArray = $Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])
434441

435442
if ($IsArray) {

Modules/CIPPCore/Public/Tools/Push-ExecGenerateReportBuilderReport.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ function Push-ExecGenerateReportBuilderReport {
6060
if ($TestResult) {
6161
if ($TestResult.TestType -eq 'Custom' -and $TestResult.ResultDataJson -and $TestResult.MarkdownTemplate) {
6262
$Block.content = $TestResult.MarkdownTemplate
63-
}
64-
if (-not $Block.content -and $TestResult.ResultMarkdown) {
63+
} elseif ($TestResult.ResultMarkdown) {
6564
$Block | Add-Member -NotePropertyName 'content' -NotePropertyValue $TestResult.ResultMarkdown -Force
6665
}
6766
}

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Email-Exchange/Spamfilter/Invoke-ListMailQuarantine.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ function Invoke-ListMailQuarantine {
1414

1515
try {
1616
$GraphRequest = if ($TenantFilter -ne 'AllTenants') {
17-
New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-QuarantineMessage' -cmdParams @{ 'PageSize' = 1000 } | Select-Object -ExcludeProperty *data.type*
17+
$Page = 1
18+
$PageSize = 1000
19+
$AllMessages = [System.Collections.Generic.List[object]]::new()
20+
do {
21+
$Results = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-QuarantineMessage' -cmdParams @{ PageSize = $PageSize; Page = $Page } | Select-Object -ExcludeProperty *data.type*
22+
if ($Results) { $AllMessages.AddRange(@($Results)) }
23+
$Page++
24+
} while (@($Results).Count -eq $PageSize)
25+
$AllMessages
1826
} else {
1927
$Table = Get-CIPPTable -TableName cacheQuarantineMessages
2028
$PartitionKey = 'QuarantineMessage'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Invoke-ListStandardsCompare {
1919
$StandardParams = @{}
2020
if ($TemplateFilter) { $StandardParams.TemplateId = $TemplateFilter }
2121
if ($TenantFilter) { $StandardParams.TenantFilter = $TenantFilter }
22-
$StandardList = Get-CIPPStandards @StandardParams
22+
$StandardList = @(Get-CIPPStandards @StandardParams) + @(Get-CIPPStandards @StandardParams -runManually $true)
2323

2424
$ScopedTemplateGuids = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
2525
$ScopedQuarantineNames = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,28 @@ function Invoke-listStandardTemplates {
4545
$Items = if ($StandardConfig -is [System.Collections.IEnumerable] -and $StandardConfig -isnot [string]) { $StandardConfig } else { @($StandardConfig) }
4646
foreach ($Item in $Items) {
4747
if ($Item.'TemplateList-Tags' -and $Item.'TemplateList-Tags'.value) {
48-
if (-not $IntuneTemplatesCache) {
49-
$IntuneTable = Get-CippTable -tablename 'templates'
50-
$IntuneFilter = "PartitionKey eq 'IntuneTemplate'"
51-
$IntuneTemplatesCache = Get-CIPPAzDataTableEntity @IntuneTable -Filter $IntuneFilter
48+
$PartitionKey = switch ($StandardName) {
49+
'ConditionalAccessTemplate' { 'CATemplate' }
50+
'IntuneTemplate' { 'IntuneTemplate' }
51+
default { 'IntuneTemplate' }
52+
}
53+
if ($PartitionKey -eq 'CATemplate') {
54+
if (-not $CATemplatesCache) {
55+
$CATable = Get-CippTable -tablename 'templates'
56+
$CAFilter = "PartitionKey eq 'CATemplate'"
57+
$CATemplatesCache = Get-CIPPAzDataTableEntity @CATable -Filter $CAFilter
58+
}
59+
$TemplatesCache = $CATemplatesCache
60+
} else {
61+
if (-not $IntuneTemplatesCache) {
62+
$IntuneTable = Get-CippTable -tablename 'templates'
63+
$IntuneFilter = "PartitionKey eq 'IntuneTemplate'"
64+
$IntuneTemplatesCache = Get-CIPPAzDataTableEntity @IntuneTable -Filter $IntuneFilter
65+
}
66+
$TemplatesCache = $IntuneTemplatesCache
5267
}
5368
$PackageName = $Item.'TemplateList-Tags'.value
54-
$LiveExpanded = @($IntuneTemplatesCache | Where-Object package -EQ $PackageName | ForEach-Object {
69+
$LiveExpanded = @($TemplatesCache | Where-Object package -EQ $PackageName | ForEach-Object {
5570
$TplJson = $_.JSON | ConvertFrom-Json -ErrorAction SilentlyContinue
5671
[pscustomobject]@{
5772
GUID = $_.RowKey

0 commit comments

Comments
 (0)