From 69600e0bb78cdb2718a3bcaca7ffe0e522eaf461 Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Sun, 25 Oct 2026 17:35:31 -0400 Subject: [PATCH 01/13] feat(intune): report device compliance and security baseline status (#2519) Implements #2519 under the #2510 epic: report the outcome Intune records on devices, not just how policies are configured. - MT.1253 Test-MtIntuneDeviceComplianceStatus: fails when the non-compliant share of evaluated managed devices is above a configurable threshold (MaxNonCompliantPercentage, default 5). Helper Get-MtManagedDeviceCompliance reads deviceManagement/managedDevices (complianceState). - MT.1254 Test-MtIntuneSecurityBaselineStatus: one result per assigned security baseline, following the InstanceSource pattern of MT.1024, failing when any device is not secure, in conflict or in error. Helper Get-MtSecurityBaseline reads the securityBaseline templates and their deviceStateSummary. Both honour the epic's decisions: - Opt-in, not on by default. Both declare Lifecycle = 'Preview', so neither runs in a default Invoke-Maester; they run with -IncludePreview. That is the opt-in mechanism the engine has today; if the epic settles on a dedicated pack, the two attributes are the only thing to change. - No new permission. Both declare Service = Graph and License = INTUNE_A and read only through DeviceManagementManagedDevices.Read.All and DeviceManagementConfiguration.Read.All, which are already in the default scopes of Get-MtGraphScope. Nothing is added to the default or preview scopes. - Neither passes on an empty or not-yet-reported source. No managed device, no reported verdict and no assigned baseline are skipped (NotApplicable / NoInstances), never a pass. A share of zero over zero devices is not a pass. Only the retrieval is guarded by try/catch, per AGENTS.md: a 401/403 from Intune RBAC maps to NotAuthorized, and anything else is rethrown so a real defect surfaces as an error instead of a silent skip. A unit test covers that. Unit tests cover the empty, non-compliant, unreadable and rethrow paths of both checks and their instance source: 22 tests. --- .../intune/Get-MtManagedDeviceCompliance.ps1 | 58 ++++ .../intune/Get-MtSecurityBaseline.ps1 | 77 +++++ .../tests/fixtures/golden/selection.json | 12 +- ...t-MtIntuneDeviceComplianceStatus.Tests.ps1 | 312 ++++++++++++++++++ tests/maester/intune/Test.MT.1253.md | 25 ++ tests/maester/intune/Test.MT.1253.ps1 | 126 +++++++ tests/maester/intune/Test.MT.1254.md | 23 ++ tests/maester/intune/Test.MT.1254.ps1 | 128 +++++++ 8 files changed, 758 insertions(+), 3 deletions(-) create mode 100644 powershell/internal/services/intune/Get-MtManagedDeviceCompliance.ps1 create mode 100644 powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 create mode 100644 powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 create mode 100644 tests/maester/intune/Test.MT.1253.md create mode 100644 tests/maester/intune/Test.MT.1253.ps1 create mode 100644 tests/maester/intune/Test.MT.1254.md create mode 100644 tests/maester/intune/Test.MT.1254.ps1 diff --git a/powershell/internal/services/intune/Get-MtManagedDeviceCompliance.ps1 b/powershell/internal/services/intune/Get-MtManagedDeviceCompliance.ps1 new file mode 100644 index 0000000000..4917579255 --- /dev/null +++ b/powershell/internal/services/intune/Get-MtManagedDeviceCompliance.ps1 @@ -0,0 +1,58 @@ +function Get-MtManagedDeviceCompliance { + <# + .SYNOPSIS + Retrieves Intune managed devices with the compliance state Intune reports for each. + + .DESCRIPTION + Queries Intune managed devices and returns a normalized object per device carrying the display name, + operating system and the compliance state Intune last evaluated. The caller buckets those states to + measure how many devices are non-compliant. + + Returns $null when the managed devices could not be read at all, so that callers can report a skip + rather than a failure. The populated result is emitted with -NoEnumerate because PowerShell unrolls + collections on output: an empty list would otherwise arrive at the caller as $null and be + indistinguishable from a read failure. This matters because Invoke-MtGraphRequest surfaces a failed + call as a non-terminating error with a null result, which collects as a single empty element. + Treating that as "no devices exist" would produce a false negative: a device-compliance result + reported purely because the signed-in account lacked permission. + + The compliance state is lower-cased on the way out. The complianceState enum is documented in lower + case, but Graph has returned mixed casing in the past, and the caller decides pass or fail on an exact + match against the state, so normalising it here keeps that decision correct. + + Errors are deliberately not caught here. The calling check guards only this retrieval, maps 401/403 + to NotAuthorized and rethrows anything else, so swallowing the exception at this level would lose the + status code and turn a permission problem into a false result. + + .EXAMPLE + Get-MtManagedDeviceCompliance + + Returns the Intune managed devices configured in the tenant with their compliance state. + #> + [CmdletBinding()] + [OutputType([System.Collections.Generic.List[pscustomobject]])] + param() + + $devices = @(Invoke-MtGraphRequest -RelativeUri 'deviceManagement/managedDevices' ` + -Select 'id', 'deviceName', 'operatingSystem', 'complianceState' -ErrorAction Stop) + + # A failed request yields elements with no id. Distinguish that from a tenant with no enrolled devices. + $usable = @($devices | Where-Object { $_ -and $_.id }) + if ($devices.Count -gt 0 -and $usable.Count -eq 0) { + Write-Verbose "Managed devices could not be read; returning null so the caller reports a skip." + return $null + } + + $result = [System.Collections.Generic.List[pscustomobject]]::new() + foreach ($device in $usable) { + $result.Add([pscustomobject]@{ + Id = $device.id + Name = $device.deviceName + OperatingSystem = $device.operatingSystem + ComplianceState = ([string]$device.complianceState).ToLowerInvariant() + }) + } + + # -NoEnumerate keeps an empty list from collapsing to $null. + Write-Output $result -NoEnumerate +} diff --git a/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 b/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 new file mode 100644 index 0000000000..2ad3ad732d --- /dev/null +++ b/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 @@ -0,0 +1,77 @@ +function Get-MtSecurityBaseline { + <# + .SYNOPSIS + Retrieves Intune security baselines with the device-state summary Intune reports for each. + + .DESCRIPTION + Lists the security baseline templates in the tenant (beta deviceManagement/templates, templateType + 'securityBaseline') and, for each, reads its device-state summary. It returns a normalized object per + baseline carrying the display name and the per-state device counts (secure, not secure, conflict, + error, unknown and not applicable), plus the total number of devices reporting against it. + + The total is included because a baseline template that no device reports against is not deployed to + anything, so it cannot have a compliance outcome. The caller uses the total to leave undeployed + baselines out, rather than reporting a pass for a baseline no device follows. + + Returns $null when the baseline templates could not be read at all, so that callers can report a skip + rather than a failure. The populated result is emitted with -NoEnumerate because PowerShell unrolls + collections on output: an empty list would otherwise arrive at the caller as $null and be + indistinguishable from a read failure. Invoke-MtGraphRequest surfaces a failed call as a + non-terminating error with a null result, which collects as a single empty element; treating that as + "no baselines exist" would hide a permission problem behind a clean result. + + A missing count is read as zero so that an undeployed baseline reports a total of zero and is left out, + instead of throwing on an absent property. + + Errors are deliberately not caught here. The calling instance source skips the family on a read + failure, so swallowing the exception at this level would lose the status code and turn a permission + problem into a false result. + + .EXAMPLE + Get-MtSecurityBaseline + + Returns the security baselines configured in the tenant with their device-state summary. + #> + [CmdletBinding()] + [OutputType([System.Collections.Generic.List[pscustomobject]])] + param() + + $templates = @(Invoke-MtGraphRequest -RelativeUri 'deviceManagement/templates' -ApiVersion beta ` + -Filter "templateType eq 'securityBaseline'" -ErrorAction Stop) + + # A failed request yields elements with no id. Distinguish that from a tenant with no baselines. + $usable = @($templates | Where-Object { $_ -and $_.id }) + if ($templates.Count -gt 0 -and $usable.Count -eq 0) { + Write-Verbose "Security baseline templates could not be read; returning null so the caller reports a skip." + return $null + } + + $result = [System.Collections.Generic.List[pscustomobject]]::new() + foreach ($template in $usable) { + $summary = Invoke-MtGraphRequest -ApiVersion beta ` + -RelativeUri "deviceManagement/templates/$($template.id)/microsoft.graph.securityBaselineTemplate/deviceStateSummary" ` + -ErrorAction Stop + + $secureCount = [int]$summary.secureCount + $notSecureCount = [int]$summary.notSecureCount + $conflictCount = [int]$summary.conflictCount + $errorCount = [int]$summary.errorCount + $unknownCount = [int]$summary.unknownCount + $notApplicableCount = [int]$summary.notApplicableCount + + $result.Add([pscustomobject]@{ + Id = $template.id + Name = $template.displayName + SecureCount = $secureCount + NotSecureCount = $notSecureCount + ConflictCount = $conflictCount + ErrorCount = $errorCount + UnknownCount = $unknownCount + NotApplicableCount = $notApplicableCount + TotalDeviceCount = $secureCount + $notSecureCount + $conflictCount + $errorCount + $unknownCount + $notApplicableCount + }) + } + + # -NoEnumerate keeps an empty list from collapsing to $null. + Write-Output $result -NoEnumerate +} diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index 05f976972c..65dd2d95e8 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -1918,7 +1918,7 @@ "AD" ] }, - "SelectedCount": 588, + "SelectedCount": 590, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -2445,6 +2445,8 @@ "MT.1250", "MT.1251", "MT.1252", + "MT.1253", + "MT.1254", "MT.1260", "ORCA.100", "ORCA.101", @@ -2527,7 +2529,7 @@ "AD" ] }, - "SelectedCount": 618, + "SelectedCount": 620, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -3086,6 +3088,8 @@ "MT.1250", "MT.1251", "MT.1252", + "MT.1253", + "MT.1254", "MT.1260", "ORCA.100", "ORCA.101", @@ -3920,7 +3924,7 @@ "AD" ] }, - "SelectedCount": 574, + "SelectedCount": 576, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -4435,6 +4439,8 @@ "MT.1250", "MT.1251", "MT.1252", + "MT.1253", + "MT.1254", "MT.1260", "ORCA.100", "ORCA.101", diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 new file mode 100644 index 0000000000..19595e1f0c --- /dev/null +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -0,0 +1,312 @@ +Describe 'Intune device compliance and security baseline status' { + BeforeAll { + Import-Module $PSScriptRoot/../../Maester.psd1 -Force + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + # These functions became native tests and an instance source; they are not exported. + Use-MtModuleFunction -Name Test-MtIntuneDeviceComplianceStatus, Test-MtIntuneSecurityBaselineStatus, Get-MtIntuneSecurityBaselineInstance + + function Get-TestDevice { + param( + [string] $ComplianceState = 'compliant', + [string] $Name = 'Device', + [string] $OperatingSystem = 'Windows' + ) + return [pscustomobject]@{ + Id = [guid]::NewGuid().ToString() + Name = $Name + OperatingSystem = $OperatingSystem + ComplianceState = $ComplianceState + } + } + + function Get-TestDeviceSet { + # Produces $Count devices of a single compliance state. + param([string] $ComplianceState, [int] $Count) + 1..$Count | ForEach-Object { Get-TestDevice -ComplianceState $ComplianceState } + } + + function Get-TestBaseline { + param( + [string] $Name = 'Windows Security Baseline', + [int] $Secure = 0, + [int] $NotSecure = 0, + [int] $Conflict = 0, + [int] $ErrorDevices = 0, + [int] $Unknown = 0, + [int] $NotApplicable = 0 + ) + return [pscustomobject]@{ + Id = [guid]::NewGuid().ToString() + Name = $Name + SecureCount = $Secure + NotSecureCount = $NotSecure + ConflictCount = $Conflict + ErrorCount = $ErrorDevices + UnknownCount = $Unknown + NotApplicableCount = $NotApplicable + TotalDeviceCount = $Secure + $NotSecure + $Conflict + $ErrorDevices + $Unknown + $NotApplicable + } + } + } + + BeforeEach { + $script:TestResult = $null + $script:SkippedBecause = $null + + Mock -ModuleName Maester Get-MtLicenseInformation { return $true } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $SkippedBecause) + + $script:TestResult = $Result + $script:SkippedBecause = $SkippedBecause + } + } + + Context 'Test-MtIntuneDeviceComplianceStatus (MT.1253)' { + It 'passes when the non-compliant share is at or below the threshold' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + return @((Get-TestDeviceSet -ComplianceState 'compliant' -Count 19) + (Get-TestDevice -ComplianceState 'noncompliant')) + } + + Test-MtIntuneDeviceComplianceStatus | Should -BeTrue + $script:TestResult | Should -Match '5%' + } + + It 'fails when the non-compliant share is above the threshold' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + return @((Get-TestDeviceSet -ComplianceState 'compliant' -Count 18) + (Get-TestDeviceSet -ComplianceState 'noncompliant' -Count 2)) + } + + Test-MtIntuneDeviceComplianceStatus | Should -BeFalse + $script:TestResult | Should -Match 'above the threshold' + } + + It 'counts conflict, error and grace-period devices as non-compliant' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + @(Get-TestDeviceSet -ComplianceState 'compliant' -Count 6) + + @(Get-TestDevice -ComplianceState 'conflict') + + @(Get-TestDevice -ComplianceState 'error') + + @(Get-TestDevice -ComplianceState 'ingraceperiod') + } + + # 3 of 9 evaluated devices are non-compliant = 33.3%, above the default 5%. + Test-MtIntuneDeviceComplianceStatus | Should -BeFalse + $script:TestResult | Should -Match '33.3%' + } + + It 'respects a custom threshold set as a parameter' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + return @((Get-TestDeviceSet -ComplianceState 'compliant' -Count 18) + (Get-TestDeviceSet -ComplianceState 'noncompliant' -Count 2)) + } + + # 10% is above the default 5% (fail) but at the custom 10% (pass). + Test-MtIntuneDeviceComplianceStatus -MaxNonCompliantPercentage 10 | Should -BeTrue + } + + It 'skips as NotApplicable when the tenant has no managed devices' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + # Mirror the real helper: emit an empty list without unrolling it to $null. + Write-Output ([System.Collections.Generic.List[pscustomobject]]::new()) -NoEnumerate + } + + $null -eq (Test-MtIntuneDeviceComplianceStatus) | Should -BeTrue + $script:SkippedBecause | Should -Be 'NotApplicable' + } + + It 'skips as NotApplicable when no device has reported a verdict' { + # unknown and configManager carry no compliance verdict, so there is nothing to measure. + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + return @((Get-TestDeviceSet -ComplianceState 'unknown' -Count 4) + (Get-TestDevice -ComplianceState 'configmanager')) + } + + $null -eq (Test-MtIntuneDeviceComplianceStatus) | Should -BeTrue + $script:SkippedBecause | Should -Be 'NotApplicable' + } + + It 'does not count unknown or configManager devices in the share' { + # 1 non-compliant out of 20 evaluated = 5% (pass). The 100 unknown devices must not dilute it. + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { + @(Get-TestDeviceSet -ComplianceState 'compliant' -Count 19) + + @(Get-TestDevice -ComplianceState 'noncompliant') + + @(Get-TestDeviceSet -ComplianceState 'unknown' -Count 100) + } + + Test-MtIntuneDeviceComplianceStatus | Should -BeTrue + } + + It 'skips as NotAuthorized when the devices cannot be read' { + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { return $null } + + $null -eq (Test-MtIntuneDeviceComplianceStatus) | Should -BeTrue + $script:SkippedBecause | Should -Be 'NotAuthorized' + } + + It 'does not disguise a non-permission failure as a skip' { + # The guard around the retrieval maps 401/403 to NotAuthorized and rethrows anything else, + # so a defect in the retrieval surfaces as an error instead of a silent skip. + Mock -ModuleName Maester Get-MtManagedDeviceCompliance { throw 'unexpected failure' } + + { Test-MtIntuneDeviceComplianceStatus } | Should -Throw + $script:SkippedBecause | Should -BeNullOrEmpty + } + } + + Context 'Get-MtManagedDeviceCompliance' { + It 'normalises the compliance state and keeps only devices with an id' { + Mock -ModuleName Maester Invoke-MtGraphRequest { + return @( + [pscustomobject]@{ id = 'd1'; deviceName = 'Laptop'; operatingSystem = 'Windows'; complianceState = 'Compliant' }, + [pscustomobject]@{ id = 'd2'; deviceName = 'Phone'; operatingSystem = 'iOS'; complianceState = 'NonCompliant' } + ) + } + + InModuleScope Maester { + $result = Get-MtManagedDeviceCompliance + $result.Count | Should -Be 2 + $result[0].ComplianceState | Should -Be 'compliant' + $result[1].ComplianceState | Should -Be 'noncompliant' + } + } + + It 'returns null when the request yields elements without an id' { + # A failed Graph call surfaces as a non-terminating error with a null result, + # which collects as a single empty element. That must not look like an empty tenant. + Mock -ModuleName Maester Invoke-MtGraphRequest { return @($null) } + + InModuleScope Maester { + $null -eq (Get-MtManagedDeviceCompliance) | Should -BeTrue + } + } + + It 'returns an empty list when the tenant genuinely has no devices' { + Mock -ModuleName Maester Invoke-MtGraphRequest { return @() } + + InModuleScope Maester { + $result = Get-MtManagedDeviceCompliance + # Must be an empty collection, NOT $null - $null means "could not read". + $null -ne $result | Should -BeTrue + $result.Count | Should -Be 0 + } + } + } + + Context 'Test-MtIntuneSecurityBaselineStatus (MT.1254)' { + It 'passes when every evaluated device is secure' { + $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Secure 25) } + + Test-MtIntuneSecurityBaselineStatus -Instance $instance | Should -BeTrue + $script:TestResult | Should -Match 'Well done' + } + + It 'fails when a device is not secure' { + $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Secure 20 -NotSecure 5) } + + Test-MtIntuneSecurityBaselineStatus -Instance $instance | Should -BeFalse + $script:TestResult | Should -Match 'do not match this baseline' + } + + It 'fails when a device is in conflict or error' { + $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Secure 20 -Conflict 1 -ErrorDevices 1) } + + Test-MtIntuneSecurityBaselineStatus -Instance $instance | Should -BeFalse + } + + It 'skips as NotApplicable when no device has an evaluated verdict' { + # Assigned, but every device is still unknown or not applicable: nothing to judge. + $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Unknown 10 -NotApplicable 3) } + + $null -eq (Test-MtIntuneSecurityBaselineStatus -Instance $instance) | Should -BeTrue + $script:SkippedBecause | Should -Be 'NotApplicable' + } + } + + Context 'Get-MtIntuneSecurityBaselineInstance (MT.1254 instance source)' { + It 'emits one instance per deployed baseline and leaves undeployed ones out' { + Mock -ModuleName Maester Get-MtSecurityBaseline { + return @( + (Get-TestBaseline -Name 'Deployed A' -Secure 10), + (Get-TestBaseline -Name 'Deployed B' -Secure 5 -NotSecure 2), + (Get-TestBaseline -Name 'Never assigned') # TotalDeviceCount = 0 + ) + } + + $instances = @(Get-MtIntuneSecurityBaselineInstance) + $instances.Count | Should -Be 2 + $instances.Title | Should -Not -Contain "Security baseline 'Never assigned' should report every device as secure." + $script:SkippedBecause | Should -BeNullOrEmpty + } + + It 'skips the family as NotAuthorized when the baselines cannot be read' { + Mock -ModuleName Maester Get-MtSecurityBaseline { return $null } + + $instances = @(Get-MtIntuneSecurityBaselineInstance) + $instances.Count | Should -Be 0 + $script:SkippedBecause | Should -Be 'NotAuthorized' + } + } + + Context 'Get-MtSecurityBaseline' { + It 'returns the per-state device counts for each baseline' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'deviceManagement/templates' + } -MockWith { + return @([pscustomobject]@{ id = 'tmpl-1'; displayName = 'Windows Baseline' }) + } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like '*deviceStateSummary*' + } -MockWith { + return [pscustomobject]@{ id = 's1'; secureCount = 8; notSecureCount = 2; conflictCount = 1; errorCount = 0; unknownCount = 3; notApplicableCount = 1 } + } + + InModuleScope Maester { + $result = Get-MtSecurityBaseline + $result.Count | Should -Be 1 + $result[0].Name | Should -Be 'Windows Baseline' + $result[0].SecureCount | Should -Be 8 + $result[0].NotSecureCount | Should -Be 2 + $result[0].TotalDeviceCount | Should -Be 15 + } + } + + It 'returns null when the templates request yields elements without an id' { + Mock -ModuleName Maester Invoke-MtGraphRequest { return @($null) } + + InModuleScope Maester { + $null -eq (Get-MtSecurityBaseline) | Should -BeTrue + } + } + + It 'returns an empty list when the tenant has no security baselines' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'deviceManagement/templates' + } -MockWith { return @() } + + InModuleScope Maester { + $result = Get-MtSecurityBaseline + $null -ne $result | Should -BeTrue + $result.Count | Should -Be 0 + } + } + + It 'treats a missing count as zero rather than throwing' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'deviceManagement/templates' + } -MockWith { + return @([pscustomobject]@{ id = 'tmpl-1'; displayName = 'Sparse Baseline' }) + } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like '*deviceStateSummary*' + } -MockWith { + # Only a secure count is present; everything else is absent. + return [pscustomobject]@{ id = 's1'; secureCount = 4 } + } + + InModuleScope Maester { + $result = Get-MtSecurityBaseline + $result[0].SecureCount | Should -Be 4 + $result[0].NotSecureCount | Should -Be 0 + $result[0].TotalDeviceCount | Should -Be 4 + } + } + } +} diff --git a/tests/maester/intune/Test.MT.1253.md b/tests/maester/intune/Test.MT.1253.md new file mode 100644 index 0000000000..4500010ebb --- /dev/null +++ b/tests/maester/intune/Test.MT.1253.md @@ -0,0 +1,25 @@ +Ensure the share of **non-compliant** Intune managed devices stays below a threshold you set. + +Maester's other Intune checks look at how device compliance policies are *configured*. This check looks at the *outcome* Intune reports: of the devices Intune has actually evaluated, how many are non-compliant. A policy can be configured perfectly and still leave a fleet full of non-compliant devices, because devices fall out of compliance for reasons a policy cannot fix: an out-of-date OS, disk encryption switched off, a missing security agent, or a device that stopped checking in. + +A device's compliance state is one of `compliant`, `noncompliant`, `conflict`, `error`, `inGracePeriod`, `unknown` or `configManager`. This test counts a device as non-compliant when it is `noncompliant`, in `conflict`, in `error`, or in the grace period (`inGracePeriod` is non-compliant but still has access to corporate resources). It leaves `unknown` and `configManager` devices out of the calculation: an `unknown` device has not reported a verdict, and a `configManager` device is evaluated by Configuration Manager, not Intune. + +The test passes when the non-compliant share of evaluated devices is at or below the threshold, which defaults to **5%**. Set your own in `maester-config.json` under `TestSettings` > `Parameters` with `MaxNonCompliantPercentage`. + +A tenant with no managed devices, or where no device has reported a verdict yet, is **skipped as not applicable**. A share of zero over zero devices is not a pass. + +#### Remediation action + +1. Navigate to the [Microsoft Intune admin center](https://intune.microsoft.com). +2. Go to **Devices** > **Monitor** > **[Noncompliant devices](https://intune.microsoft.com/#view/Microsoft_Intune_DeviceSettings/DevicesMenu/~/complianceReport)** to see which devices are non-compliant and which setting each one fails. +3. Work through the devices: update the operating system, turn on the required protection, or re-enroll devices that stopped checking in. +4. Configure **Actions for noncompliance** on your compliance policies so users are notified and given time to remediate before a device is blocked. + +#### Related links + +- [Microsoft Intune admin center - Device compliance](https://intune.microsoft.com/#view/Microsoft_Intune_DeviceSettings/DevicesMenu/~/compliance) +- [Microsoft Learn - Monitor device compliance](https://learn.microsoft.com/intune/intune-service/protect/compliance-policy-monitor) +- [Microsoft Learn - Device compliance states](https://learn.microsoft.com/graph/api/resources/intune-devices-compliancestate) + + +%TestResult% diff --git a/tests/maester/intune/Test.MT.1253.ps1 b/tests/maester/intune/Test.MT.1253.ps1 new file mode 100644 index 0000000000..7d5040dbab --- /dev/null +++ b/tests/maester/intune/Test.MT.1253.ps1 @@ -0,0 +1,126 @@ +function Test-MtIntuneDeviceComplianceStatus { + <# + .SYNOPSIS + Ensure the share of non-compliant Intune managed devices stays below a configured threshold. + + .DESCRIPTION + Maester's other Intune checks look at how compliance policies are configured. This check looks at the + outcome Intune reports: of the devices Intune has actually evaluated, how many are non-compliant. + + A device's complianceState is one of compliant, noncompliant, conflict, error, inGracePeriod, unknown + or configManager. This test counts a device as non-compliant when it is noncompliant, in conflict, + in error, or in the grace period (which is non-compliant but still has access). It leaves unknown and + configManager devices out of the calculation: an unknown device has not reported a verdict, and a + configManager device is evaluated by Configuration Manager, not Intune. + + The test passes when the non-compliant share of evaluated devices is at or below the threshold, which + defaults to 5% and can be set per tenant. It fails when the share is above the threshold. + + It does not pass when Intune has no managed devices, or when no device has reported a verdict yet: a + tenant with nothing to measure is skipped as not applicable, never reported as compliant. A share of + zero over zero devices is not a pass. + + .EXAMPLE + Test-MtIntuneDeviceComplianceStatus + + Returns true if the non-compliant share of evaluated Intune managed devices is at or below 5%. + + .EXAMPLE + Test-MtIntuneDeviceComplianceStatus -MaxNonCompliantPercentage 10 + + Returns true if the non-compliant share of evaluated Intune managed devices is at or below 10%. + + .LINK + https://maester.dev/docs/commands/Test-MtIntuneDeviceComplianceStatus + #> + [MaesterTest( + Id = 'MT.1253', + Title = 'Non-compliant Intune managed devices should be below the configured threshold.', + Product = 'intune', + Feature = 'device-compliance', + Area = 'devices', + ResourceType = 'Device', + Severity = 'Medium', + UserImpact = 'Low', + ImplementationCost = 'Medium', + Mitre = 'None', + Lifecycle = 'Preview', + Service = 'Graph', + License = 'INTUNE_A', + Author = 'earbona23' + )] + [CmdletBinding()] + [OutputType([bool])] + param( + # The highest share of evaluated devices that may be non-compliant before this test fails, as a + # percentage. Set it per tenant in maester-config.json (TestSettings > Parameters). + [ValidateRange(0, 100)] + [int] $MaxNonCompliantPercentage = 5 + ) + + Write-Verbose "Querying Intune managed devices..." + + # Only the retrieval is guarded. A 401/403 from Intune RBAC is a missing permission, which is a + # skip; anything else is left to surface as an error, so a real defect in this test is never + # reported as a skip. + try { + $devices = Get-MtManagedDeviceCompliance + } catch { + if ($_.Exception.Response -and $_.Exception.Response.StatusCode -in @(401, 403)) { + Add-MtTestResultDetail -SkippedBecause NotAuthorized + return $null + } + throw + } + + if ($null -eq $devices) { + # The helper could not read the data at all, most commonly a 403 from Intune RBAC. + # Report a skip rather than a false result. + Add-MtTestResultDetail -SkippedBecause NotAuthorized + return $null + } + + # States that carry a compliance verdict. unknown has not reported one, and configManager devices + # are evaluated by Configuration Manager, so both are left out of the share. + $evaluatedStates = @('compliant', 'noncompliant', 'conflict', 'error', 'ingraceperiod') + $nonCompliantStates = @('noncompliant', 'conflict', 'error', 'ingraceperiod') + + $evaluated = @($devices | Where-Object { $_.ComplianceState -in $evaluatedStates }) + if ($evaluated.Count -eq 0) { + # Nothing to measure. A share of zero non-compliant over zero evaluated devices is not a pass: + # skip as not applicable so an empty or not-yet-reported tenant is never reported as compliant. + Add-MtTestResultDetail -SkippedBecause NotApplicable + return $null + } + + $nonCompliant = @($devices | Where-Object { $_.ComplianceState -in $nonCompliantStates }) + $percentage = [math]::Round(($nonCompliant.Count / $evaluated.Count) * 100, 1) + $testResult = $percentage -le $MaxNonCompliantPercentage + + $counts = [ordered]@{ + 'Compliant' = @($devices | Where-Object { $_.ComplianceState -eq 'compliant' }).Count + 'Non-compliant' = @($devices | Where-Object { $_.ComplianceState -eq 'noncompliant' }).Count + 'In grace period' = @($devices | Where-Object { $_.ComplianceState -eq 'ingraceperiod' }).Count + 'Conflict' = @($devices | Where-Object { $_.ComplianceState -eq 'conflict' }).Count + 'Error' = @($devices | Where-Object { $_.ComplianceState -eq 'error' }).Count + 'Unknown (not counted)' = @($devices | Where-Object { $_.ComplianceState -eq 'unknown' }).Count + 'Config Manager (not counted)' = @($devices | Where-Object { $_.ComplianceState -eq 'configmanager' }).Count + } + + $testResultMarkdown = "Evaluated $($evaluated.Count) of $($devices.Count) managed device(s). " + $testResultMarkdown += "**$($nonCompliant.Count)** ($percentage%) are non-compliant; the threshold is $MaxNonCompliantPercentage%.`n`n" + $testResultMarkdown += "| Compliance state | Devices |`n" + $testResultMarkdown += "| --- | --- |`n" + foreach ($state in $counts.Keys) { + $testResultMarkdown += "| $state | $($counts[$state]) |`n" + } + + if ($testResult) { + $testResultMarkdown += "`nWell done. The non-compliant share is at or below the threshold." + } else { + $testResultMarkdown += "`nThe non-compliant share is above the threshold. Review the non-compliant devices in Intune and bring them back into compliance, or investigate why they cannot report as compliant." + } + + Add-MtTestResultDetail -Result $testResultMarkdown + return $testResult +} diff --git a/tests/maester/intune/Test.MT.1254.md b/tests/maester/intune/Test.MT.1254.md new file mode 100644 index 0000000000..ba51cce05c --- /dev/null +++ b/tests/maester/intune/Test.MT.1254.md @@ -0,0 +1,23 @@ +Ensure devices **assigned a security baseline** comply with it. + +A security baseline is Microsoft's recommended set of hardening settings for a product (Windows, Microsoft Edge, Microsoft Defender for Endpoint and others). Assigning one is only half the job: a device can be assigned a baseline and still deviate from it, because a setting conflicts with another policy, because the device has not applied it, or because enforcement errored. Intune reports that outcome per baseline, and this check surfaces it. + +This test runs **once per assigned security baseline** — a baseline that reports against at least one device. For each, Intune summarises its devices as secure, not secure, in conflict, in error, unknown or not applicable. The baseline **passes** when every device Intune has evaluated against it is secure, and **fails** when any device is not secure, in conflict, or in error. + +A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is **skipped as not applicable**. A tenant with no assigned baselines is skipped too: there is nothing to report on, and that is never a pass. + +#### Remediation action + +1. Navigate to the [Microsoft Intune admin center](https://intune.microsoft.com). +2. Go to **Endpoint security** > **[Security baselines](https://intune.microsoft.com/#view/Microsoft_Intune_Workflows/SecurityManagementMenu/~/securityBaselines)** and open the baseline named in the result. +3. On the baseline's **Overview**, review the per-device and per-setting state to see which devices are not secure or in conflict and which setting each one deviates on. +4. Resolve conflicts (a second policy setting the same value differently), then remediate or re-sync the affected devices. + +#### Related links + +- [Microsoft Intune admin center - Security baselines](https://intune.microsoft.com/#view/Microsoft_Intune_Workflows/SecurityManagementMenu/~/securityBaselines) +- [Microsoft Learn - Use security baselines to configure Windows devices in Intune](https://learn.microsoft.com/intune/intune-service/protect/security-baselines) +- [Microsoft Learn - Monitor security baselines and profiles](https://learn.microsoft.com/intune/intune-service/protect/security-baselines-monitor) + + +%TestResult% diff --git a/tests/maester/intune/Test.MT.1254.ps1 b/tests/maester/intune/Test.MT.1254.ps1 new file mode 100644 index 0000000000..a6d9b3a491 --- /dev/null +++ b/tests/maester/intune/Test.MT.1254.ps1 @@ -0,0 +1,128 @@ +function Get-MtIntuneSecurityBaselineInstance { + <# + .SYNOPSIS + Returns one MT.1254 instance per assigned Intune security baseline. + + .DESCRIPTION + Instance source of the MT.1254 family. The suffix is the security baseline's template ID + (MT.1254.) and the title names the baseline. Only baselines that are actually deployed to + devices are emitted: a baseline template with no reporting device is not an assigned baseline and must + not surface as a passing result. + + When the baselines cannot be read at all (typically a 403 from Intune RBAC) the whole family is + skipped rather than reported, because Add-MtTestResultDetail -SkippedBecause in an instance source + skips the family. When there are no assigned baselines the source emits nothing, and the engine skips + the family with NoInstances; it is never a pass. + #> + [CmdletBinding()] + [OutputType([pscustomobject])] + param() + + $baselines = Get-MtSecurityBaseline + if ($null -eq $baselines) { + Add-MtTestResultDetail -SkippedBecause NotAuthorized + return + } + + foreach ($baseline in $baselines) { + # Only baselines reporting against at least one device. An undeployed template has no outcome to + # judge, so leaving it out keeps it from surfacing as a (false) passing baseline. + if ($baseline.TotalDeviceCount -le 0) { continue } + [pscustomobject]@{ + Id = $baseline.Id + Title = "Security baseline '$($baseline.Name)' should report every device as secure." + Data = $baseline + } + } +} + +function Test-MtIntuneSecurityBaselineStatus { + <# + .SYNOPSIS + Ensure devices assigned a security baseline comply with it. + + .DESCRIPTION + Maester's other Intune checks look at how policies are configured. This check looks at the outcome + Intune reports for each assigned security baseline: whether the devices the baseline is deployed to + actually match it. + + It runs once per assigned security baseline (deviceManagement/templates of type securityBaseline that + report against at least one device). For each, Intune summarises its devices as secure, not secure, + in conflict, in error, unknown or not applicable. The baseline passes when every device Intune has + evaluated against it is secure, and fails when any device is not secure, in conflict, or in error. + + A baseline that is assigned but has no evaluated device yet (every device still unknown or not + applicable) is skipped as not applicable: a baseline nothing has reported a secure-or-not verdict on + is not a compliant baseline. + + .EXAMPLE + Test-MtIntuneSecurityBaselineStatus + + Returns one result per assigned security baseline, true when every evaluated device is secure. + + .LINK + https://maester.dev/docs/commands/Test-MtIntuneSecurityBaselineStatus + #> + [MaesterTest( + Id = 'MT.1254', + Title = 'Devices assigned a security baseline should comply with it.', + Product = 'intune', + Feature = 'endpoint-security', + Area = 'devices', + ResourceType = 'Policy', + Severity = 'Medium', + UserImpact = 'Low', + ImplementationCost = 'Medium', + Mitre = 'None', + Lifecycle = 'Preview', + Service = 'Graph', + License = 'INTUNE_A', + InstanceSource = 'Get-MtIntuneSecurityBaselineInstance', + Author = 'earbona23' + )] + [CmdletBinding()] + [OutputType([bool])] + param( + # The baseline to check, supplied by the engine. + $Instance + ) + + $baseline = $Instance.Data + $secureCount = [int]$baseline.SecureCount + $notSecureCount = [int]$baseline.NotSecureCount + $conflictCount = [int]$baseline.ConflictCount + $errorCount = [int]$baseline.ErrorCount + $unknownCount = [int]$baseline.UnknownCount + $notApplicableCount = [int]$baseline.NotApplicableCount + + $evaluatedCount = $secureCount + $notSecureCount + $conflictCount + $errorCount + if ($evaluatedCount -le 0) { + # Assigned, but no device has reported a secure or not-secure verdict yet. There is no outcome to + # judge, so skip rather than pass. + Add-MtTestResultDetail -SkippedBecause NotApplicable + return $null + } + + $deviatingCount = $notSecureCount + $conflictCount + $errorCount + $testResult = $deviatingCount -eq 0 + + $testResultMarkdown = "Security baseline **$($baseline.Name)** is reporting against $($baseline.TotalDeviceCount) device(s).`n`n" + $testResultMarkdown += "| Device state | Devices |`n" + $testResultMarkdown += "| --- | --- |`n" + $testResultMarkdown += "| Secure | $secureCount |`n" + $testResultMarkdown += "| Not secure | $notSecureCount |`n" + $testResultMarkdown += "| Conflict | $conflictCount |`n" + $testResultMarkdown += "| Error | $errorCount |`n" + $testResultMarkdown += "| Unknown | $unknownCount |`n" + $testResultMarkdown += "| Not applicable | $notApplicableCount |`n" + + if ($testResult) { + $testResultMarkdown += "`nWell done. Every device evaluated against this baseline is secure." + } else { + $testResultMarkdown += "`n**$deviatingCount** of $evaluatedCount evaluated device(s) do not match this baseline. " + $testResultMarkdown += "Review the baseline in Intune to see which setting each device deviates on, and remediate the devices or resolve the conflicting policy." + } + + Add-MtTestResultDetail -Result $testResultMarkdown + return $testResult +} From 67756fa279d20140a96d1823a6b49acb6a5081f4 Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Thu, 5 Nov 2026 23:27:58 -0400 Subject: [PATCH 02/13] fix(MT.1253): UserImpact is Medium, not Low The attribute review is right: remediating a non-compliant device reaches its owner. They re-enrol it, update the OS or turn protection back on, and the recommended configuration notifies them and gives them time before the device is blocked. Under the rubric that is Medium, not Low. --- tests/maester/intune/Test.MT.1253.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/maester/intune/Test.MT.1253.ps1 b/tests/maester/intune/Test.MT.1253.ps1 index 7d5040dbab..2a07210ab3 100644 --- a/tests/maester/intune/Test.MT.1253.ps1 +++ b/tests/maester/intune/Test.MT.1253.ps1 @@ -41,7 +41,7 @@ Area = 'devices', ResourceType = 'Device', Severity = 'Medium', - UserImpact = 'Low', + UserImpact = 'Medium', ImplementationCost = 'Medium', Mitre = 'None', Lifecycle = 'Preview', From e9f128b6eff914ef4213d2a8e83989d1c15cf254 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sat, 7 Nov 2026 17:00:00 -0400 Subject: [PATCH 03/13] fix(MT.1254): map a 401/403 baseline read to the skip the source documents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function's own description says a read failure skips the family. It only held for one of the helper's two failure paths. `Get-MtSecurityBaseline` returns $null when the response comes back with no usable ids, and that path was covered. It also lets a terminating error through on purpose — its description says so — and that path was not: a 403 from Intune RBAC reached the engine as InstanceSourceFailed rather than NotAuthorized, so a missing permission was reported as a broken test. The guard is the one MT.1253 already uses in this same pull request: only the retrieval is wrapped, only 401/403 becomes a skip, and anything else is rethrown, so a real defect never hides behind a skip. Two cases added, mirroring the MT.1253 pair: the 403 now skips, and a failure that is not a permission problem still throws. 24 of 24 with the fix; with Test.MT.1254.ps1 reverted the 403 case is the only one that fails. --- ...t-MtIntuneDeviceComplianceStatus.Tests.ps1 | 25 +++++++++++++++++++ tests/maester/intune/Test.MT.1254.ps1 | 17 ++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index 19595e1f0c..3d8d94023c 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -243,6 +243,31 @@ $instances.Count | Should -Be 0 $script:SkippedBecause | Should -Be 'NotAuthorized' } + + It 'skips the family as NotAuthorized when the baseline read throws 403' { + # The helper has two failure paths. The case above is the one where it returns $null; + # this is the one where it lets a terminating error through, which used to reach the + # engine as InstanceSourceFailed rather than the skip this source documents. + Mock -ModuleName Maester Get-MtSecurityBaseline { + $respuesta = [pscustomobject]@{ StatusCode = 403 } + $excepcion = [System.Exception]::new('Forbidden') + $excepcion | Add-Member -NotePropertyName Response -NotePropertyValue $respuesta -Force + throw $excepcion + } + + $instances = @(Get-MtIntuneSecurityBaselineInstance) + $instances.Count | Should -Be 0 + $script:SkippedBecause | Should -Be 'NotAuthorized' + } + + It 'does not disguise a non-permission baseline failure as a skip' { + # Same reasoning as the MT.1253 guard above: anything that is not 401/403 is rethrown, + # so a defect in the retrieval surfaces as an error instead of a silent skip. + Mock -ModuleName Maester Get-MtSecurityBaseline { throw 'unexpected failure' } + + { Get-MtIntuneSecurityBaselineInstance } | Should -Throw + $script:SkippedBecause | Should -BeNullOrEmpty + } } Context 'Get-MtSecurityBaseline' { diff --git a/tests/maester/intune/Test.MT.1254.ps1 b/tests/maester/intune/Test.MT.1254.ps1 index a6d9b3a491..00b9eaa2ce 100644 --- a/tests/maester/intune/Test.MT.1254.ps1 +++ b/tests/maester/intune/Test.MT.1254.ps1 @@ -18,7 +18,22 @@ [OutputType([pscustomobject])] param() - $baselines = Get-MtSecurityBaseline + # Only the retrieval is guarded, and only 401/403. The helper has two failure paths: it returns + # $null when the response comes back with no usable ids, which the check below already covered, + # and it lets a terminating error through, which did not reach that check and surfaced as + # InstanceSourceFailed instead of the skip this function documents. Anything that is not a + # permission problem is still left to surface, so a real defect is never reported as a skip. + # Same shape as MT.1253 in this pull request. + try { + $baselines = Get-MtSecurityBaseline + } catch { + if ($_.Exception.Response -and $_.Exception.Response.StatusCode -in @(401, 403)) { + Add-MtTestResultDetail -SkippedBecause NotAuthorized + return + } + throw + } + if ($null -eq $baselines) { Add-MtTestResultDetail -SkippedBecause NotAuthorized return From 0327cc027a3f140d188fc6154354539ee82c5a94 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 8 Nov 2026 00:40:19 -0400 Subject: [PATCH 04/13] chore: renumber to the next free MT sequence (MT.1253/1254 -> MT.1267/1268) MT.1253-1258 are already reserved by Cloud-Architekt on #697 (28 Oct) and used in #2705, so this PR had taken numbers that were not free. Renumbered from MT.1267, the next free number after MT.1266, and reserved the new range on #697. The golden selection fixture was regenerated with build/golden/Export-MtGoldenFixture.ps1 rather than edited by hand, as the file itself asks. --- powershell/tests/fixtures/golden/selection.json | 12 ++++++------ .../Test-MtIntuneDeviceComplianceStatus.Tests.ps1 | 8 ++++---- tests/maester/entra/Test.MT.1260.md | 2 +- .../intune/{Test.MT.1253.md => Test.MT.1267.md} | 0 .../intune/{Test.MT.1253.ps1 => Test.MT.1267.ps1} | 2 +- .../intune/{Test.MT.1254.md => Test.MT.1268.md} | 0 .../intune/{Test.MT.1254.ps1 => Test.MT.1268.ps1} | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) rename tests/maester/intune/{Test.MT.1253.md => Test.MT.1267.md} (100%) rename tests/maester/intune/{Test.MT.1253.ps1 => Test.MT.1267.ps1} (99%) rename tests/maester/intune/{Test.MT.1254.md => Test.MT.1268.md} (100%) rename tests/maester/intune/{Test.MT.1254.ps1 => Test.MT.1268.ps1} (95%) diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index e21e0192e3..1d00c085f9 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -2448,11 +2448,11 @@ "MT.1250", "MT.1251", "MT.1252", - "MT.1253", - "MT.1254", "MT.1259", "MT.1260", "MT.1265", + "MT.1267", + "MT.1268", "ORCA.100", "ORCA.101", "ORCA.102", @@ -3093,11 +3093,11 @@ "MT.1250", "MT.1251", "MT.1252", - "MT.1253", - "MT.1254", "MT.1259", "MT.1260", "MT.1265", + "MT.1267", + "MT.1268", "ORCA.100", "ORCA.101", "ORCA.102", @@ -4447,11 +4447,11 @@ "MT.1250", "MT.1251", "MT.1252", - "MT.1253", - "MT.1254", "MT.1259", "MT.1260", "MT.1265", + "MT.1267", + "MT.1268", "ORCA.100", "ORCA.101", "ORCA.102", diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index 3d8d94023c..35384bb04b 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -62,7 +62,7 @@ } } - Context 'Test-MtIntuneDeviceComplianceStatus (MT.1253)' { + Context 'Test-MtIntuneDeviceComplianceStatus (MT.1267)' { It 'passes when the non-compliant share is at or below the threshold' { Mock -ModuleName Maester Get-MtManagedDeviceCompliance { return @((Get-TestDeviceSet -ComplianceState 'compliant' -Count 19) + (Get-TestDevice -ComplianceState 'noncompliant')) @@ -190,7 +190,7 @@ } } - Context 'Test-MtIntuneSecurityBaselineStatus (MT.1254)' { + Context 'Test-MtIntuneSecurityBaselineStatus (MT.1268)' { It 'passes when every evaluated device is secure' { $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Secure 25) } @@ -220,7 +220,7 @@ } } - Context 'Get-MtIntuneSecurityBaselineInstance (MT.1254 instance source)' { + Context 'Get-MtIntuneSecurityBaselineInstance (MT.1268 instance source)' { It 'emits one instance per deployed baseline and leaves undeployed ones out' { Mock -ModuleName Maester Get-MtSecurityBaseline { return @( @@ -261,7 +261,7 @@ } It 'does not disguise a non-permission baseline failure as a skip' { - # Same reasoning as the MT.1253 guard above: anything that is not 401/403 is rethrown, + # Same reasoning as the MT.1267 guard above: anything that is not 401/403 is rethrown, # so a defect in the retrieval surfaces as an error instead of a silent skip. Mock -ModuleName Maester Get-MtSecurityBaseline { throw 'unexpected failure' } diff --git a/tests/maester/entra/Test.MT.1260.md b/tests/maester/entra/Test.MT.1260.md index 3d94ff2ab7..3ec1e0a184 100644 --- a/tests/maester/entra/Test.MT.1260.md +++ b/tests/maester/entra/Test.MT.1260.md @@ -8,7 +8,7 @@ If a reported user holds a privileged directory role, active or PIM-eligible, th The check needs the Microsoft Graph permission `IdentityRiskyUser.Read.All`, which Maester does not request by default. Without it the check is skipped. Connect with `Connect-Maester -IncludePreview`, or grant the permission to the app registration that runs Maester. -A companion check, MT.1261, is planned to report on medium-risk users. This check is about the outcome (users actually left unremediated). It is complementary to MT.1253, which checks that a Conditional Access policy requiring risk remediation is in place; one checks the control, this one checks the result. +A companion check, MT.1261, is planned to report on medium-risk users. This check is about the outcome (users actually left unremediated). It is complementary to MT.1267, which checks that a Conditional Access policy requiring risk remediation is in place; one checks the control, this one checks the result. #### Remediation action diff --git a/tests/maester/intune/Test.MT.1253.md b/tests/maester/intune/Test.MT.1267.md similarity index 100% rename from tests/maester/intune/Test.MT.1253.md rename to tests/maester/intune/Test.MT.1267.md diff --git a/tests/maester/intune/Test.MT.1253.ps1 b/tests/maester/intune/Test.MT.1267.ps1 similarity index 99% rename from tests/maester/intune/Test.MT.1253.ps1 rename to tests/maester/intune/Test.MT.1267.ps1 index 2a07210ab3..0f50195f46 100644 --- a/tests/maester/intune/Test.MT.1253.ps1 +++ b/tests/maester/intune/Test.MT.1267.ps1 @@ -34,7 +34,7 @@ https://maester.dev/docs/commands/Test-MtIntuneDeviceComplianceStatus #> [MaesterTest( - Id = 'MT.1253', + Id = 'MT.1267', Title = 'Non-compliant Intune managed devices should be below the configured threshold.', Product = 'intune', Feature = 'device-compliance', diff --git a/tests/maester/intune/Test.MT.1254.md b/tests/maester/intune/Test.MT.1268.md similarity index 100% rename from tests/maester/intune/Test.MT.1254.md rename to tests/maester/intune/Test.MT.1268.md diff --git a/tests/maester/intune/Test.MT.1254.ps1 b/tests/maester/intune/Test.MT.1268.ps1 similarity index 95% rename from tests/maester/intune/Test.MT.1254.ps1 rename to tests/maester/intune/Test.MT.1268.ps1 index 00b9eaa2ce..46af6ec620 100644 --- a/tests/maester/intune/Test.MT.1254.ps1 +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -1,11 +1,11 @@ function Get-MtIntuneSecurityBaselineInstance { <# .SYNOPSIS - Returns one MT.1254 instance per assigned Intune security baseline. + Returns one MT.1268 instance per assigned Intune security baseline. .DESCRIPTION - Instance source of the MT.1254 family. The suffix is the security baseline's template ID - (MT.1254.) and the title names the baseline. Only baselines that are actually deployed to + Instance source of the MT.1268 family. The suffix is the security baseline's template ID + (MT.1268.) and the title names the baseline. Only baselines that are actually deployed to devices are emitted: a baseline template with no reporting device is not an assigned baseline and must not surface as a passing result. @@ -23,7 +23,7 @@ # and it lets a terminating error through, which did not reach that check and surfaced as # InstanceSourceFailed instead of the skip this function documents. Anything that is not a # permission problem is still left to surface, so a real defect is never reported as a skip. - # Same shape as MT.1253 in this pull request. + # Same shape as MT.1267 in this pull request. try { $baselines = Get-MtSecurityBaseline } catch { @@ -79,7 +79,7 @@ function Test-MtIntuneSecurityBaselineStatus { https://maester.dev/docs/commands/Test-MtIntuneSecurityBaselineStatus #> [MaesterTest( - Id = 'MT.1254', + Id = 'MT.1268', Title = 'Devices assigned a security baseline should comply with it.', Product = 'intune', Feature = 'endpoint-security', From 0316d018925f0d4167937ef5e0e82b232622d375 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 8 Nov 2026 00:42:30 -0400 Subject: [PATCH 05/13] fix: restore the MT.1253 reference in MT.1260.md The renumbering swept this file by mistake. The MT.1253 named here is @Cloud-Architekt's reserved Conditional Access check, not the Intune check this PR renumbered, so the reference must stay as it was on main. --- tests/maester/entra/Test.MT.1260.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/maester/entra/Test.MT.1260.md b/tests/maester/entra/Test.MT.1260.md index 3ec1e0a184..3d94ff2ab7 100644 --- a/tests/maester/entra/Test.MT.1260.md +++ b/tests/maester/entra/Test.MT.1260.md @@ -8,7 +8,7 @@ If a reported user holds a privileged directory role, active or PIM-eligible, th The check needs the Microsoft Graph permission `IdentityRiskyUser.Read.All`, which Maester does not request by default. Without it the check is skipped. Connect with `Connect-Maester -IncludePreview`, or grant the permission to the app registration that runs Maester. -A companion check, MT.1261, is planned to report on medium-risk users. This check is about the outcome (users actually left unremediated). It is complementary to MT.1267, which checks that a Conditional Access policy requiring risk remediation is in place; one checks the control, this one checks the result. +A companion check, MT.1261, is planned to report on medium-risk users. This check is about the outcome (users actually left unremediated). It is complementary to MT.1253, which checks that a Conditional Access policy requiring risk remediation is in place; one checks the control, this one checks the result. #### Remediation action From 95b5fc187afc0f10c214334ad153fff2d0c99bb6 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:53:13 -0400 Subject: [PATCH 06/13] fix: the two test guides are Markdown, so they carry no byte order mark FileEncoding.Tests.ps1 on main checks the rule in website/docs/contributing.md: PowerShell files are UTF-8 with a BOM, Markdown files - test guides included - are UTF-8 without one. Both guides in this PR had one, which CI caught. --- tests/maester/intune/Test.MT.1267.md | 2 +- tests/maester/intune/Test.MT.1268.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/maester/intune/Test.MT.1267.md b/tests/maester/intune/Test.MT.1267.md index 4500010ebb..9f5064520c 100644 --- a/tests/maester/intune/Test.MT.1267.md +++ b/tests/maester/intune/Test.MT.1267.md @@ -1,4 +1,4 @@ -Ensure the share of **non-compliant** Intune managed devices stays below a threshold you set. +Ensure the share of **non-compliant** Intune managed devices stays below a threshold you set. Maester's other Intune checks look at how device compliance policies are *configured*. This check looks at the *outcome* Intune reports: of the devices Intune has actually evaluated, how many are non-compliant. A policy can be configured perfectly and still leave a fleet full of non-compliant devices, because devices fall out of compliance for reasons a policy cannot fix: an out-of-date OS, disk encryption switched off, a missing security agent, or a device that stopped checking in. diff --git a/tests/maester/intune/Test.MT.1268.md b/tests/maester/intune/Test.MT.1268.md index ba51cce05c..358f61c2ed 100644 --- a/tests/maester/intune/Test.MT.1268.md +++ b/tests/maester/intune/Test.MT.1268.md @@ -1,4 +1,4 @@ -Ensure devices **assigned a security baseline** comply with it. +Ensure devices **assigned a security baseline** comply with it. A security baseline is Microsoft's recommended set of hardening settings for a product (Windows, Microsoft Edge, Microsoft Defender for Endpoint and others). Assigning one is only half the job: a device can be assigned a baseline and still deviate from it, because a setting conflicts with another policy, because the device has not applied it, or because enforcement errored. Intune reports that outcome per baseline, and this check surfaces it. From af213dfd39bb6a6f541d03d92d4380bfd4961df4 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:54:58 -0400 Subject: [PATCH 07/13] style: canonical attribute property order Ran the files through build/migration/Convert-MtTestAttributes.ps1, which the repo uses to keep [MaesterTest(...)] properties in one order. main reports Reordered=0 and these were the only files in the tree that did not, which came from how they were written rather than from any change in behaviour. The tool now reports Changed=0 Reordered=0 here too. No values were altered. --- tests/maester/intune/Test.MT.1267.ps1 | 2 +- tests/maester/intune/Test.MT.1268.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/maester/intune/Test.MT.1267.ps1 b/tests/maester/intune/Test.MT.1267.ps1 index 0f50195f46..c6298eb6cd 100644 --- a/tests/maester/intune/Test.MT.1267.ps1 +++ b/tests/maester/intune/Test.MT.1267.ps1 @@ -44,9 +44,9 @@ UserImpact = 'Medium', ImplementationCost = 'Medium', Mitre = 'None', - Lifecycle = 'Preview', Service = 'Graph', License = 'INTUNE_A', + Lifecycle = 'Preview', Author = 'earbona23' )] [CmdletBinding()] diff --git a/tests/maester/intune/Test.MT.1268.ps1 b/tests/maester/intune/Test.MT.1268.ps1 index 46af6ec620..d4fd34101e 100644 --- a/tests/maester/intune/Test.MT.1268.ps1 +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -89,9 +89,9 @@ function Test-MtIntuneSecurityBaselineStatus { UserImpact = 'Low', ImplementationCost = 'Medium', Mitre = 'None', - Lifecycle = 'Preview', Service = 'Graph', License = 'INTUNE_A', + Lifecycle = 'Preview', InstanceSource = 'Get-MtIntuneSecurityBaselineInstance', Author = 'earbona23' )] From 4be316c63a50dae3e726dd3e47ba9021611c0856 Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Wed, 11 Nov 2026 11:16:26 -0400 Subject: [PATCH 08/13] fix(intune): spell out Maximum in MT.1267's parameter name `MaxNonCompliantPercentage` becomes `MaximumNonCompliantPercentage`. #2758 added the parameter-name rules after this branch was opened, and `powershell/tests/general/TestParameterNames.Tests.ps1` flags a name starting with `Max` that is not `Maximum`. Every other limit in the repository already spells it out (24 parameters, none abbreviated). --- .../Test-MtIntuneDeviceComplianceStatus.Tests.ps1 | 2 +- tests/maester/intune/Test.MT.1267.md | 2 +- tests/maester/intune/Test.MT.1267.ps1 | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index 35384bb04b..b916b21ff4 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -100,7 +100,7 @@ } # 10% is above the default 5% (fail) but at the custom 10% (pass). - Test-MtIntuneDeviceComplianceStatus -MaxNonCompliantPercentage 10 | Should -BeTrue + Test-MtIntuneDeviceComplianceStatus -MaximumNonCompliantPercentage 10 | Should -BeTrue } It 'skips as NotApplicable when the tenant has no managed devices' { diff --git a/tests/maester/intune/Test.MT.1267.md b/tests/maester/intune/Test.MT.1267.md index 9f5064520c..fb4883a478 100644 --- a/tests/maester/intune/Test.MT.1267.md +++ b/tests/maester/intune/Test.MT.1267.md @@ -4,7 +4,7 @@ Maester's other Intune checks look at how device compliance policies are *config A device's compliance state is one of `compliant`, `noncompliant`, `conflict`, `error`, `inGracePeriod`, `unknown` or `configManager`. This test counts a device as non-compliant when it is `noncompliant`, in `conflict`, in `error`, or in the grace period (`inGracePeriod` is non-compliant but still has access to corporate resources). It leaves `unknown` and `configManager` devices out of the calculation: an `unknown` device has not reported a verdict, and a `configManager` device is evaluated by Configuration Manager, not Intune. -The test passes when the non-compliant share of evaluated devices is at or below the threshold, which defaults to **5%**. Set your own in `maester-config.json` under `TestSettings` > `Parameters` with `MaxNonCompliantPercentage`. +The test passes when the non-compliant share of evaluated devices is at or below the threshold, which defaults to **5%**. Set your own in `maester-config.json` under `TestSettings` > `Parameters` with `MaximumNonCompliantPercentage`. A tenant with no managed devices, or where no device has reported a verdict yet, is **skipped as not applicable**. A share of zero over zero devices is not a pass. diff --git a/tests/maester/intune/Test.MT.1267.ps1 b/tests/maester/intune/Test.MT.1267.ps1 index c6298eb6cd..11c1d016b1 100644 --- a/tests/maester/intune/Test.MT.1267.ps1 +++ b/tests/maester/intune/Test.MT.1267.ps1 @@ -26,7 +26,7 @@ Returns true if the non-compliant share of evaluated Intune managed devices is at or below 5%. .EXAMPLE - Test-MtIntuneDeviceComplianceStatus -MaxNonCompliantPercentage 10 + Test-MtIntuneDeviceComplianceStatus -MaximumNonCompliantPercentage 10 Returns true if the non-compliant share of evaluated Intune managed devices is at or below 10%. @@ -55,7 +55,7 @@ # The highest share of evaluated devices that may be non-compliant before this test fails, as a # percentage. Set it per tenant in maester-config.json (TestSettings > Parameters). [ValidateRange(0, 100)] - [int] $MaxNonCompliantPercentage = 5 + [int] $MaximumNonCompliantPercentage = 5 ) Write-Verbose "Querying Intune managed devices..." @@ -95,7 +95,7 @@ $nonCompliant = @($devices | Where-Object { $_.ComplianceState -in $nonCompliantStates }) $percentage = [math]::Round(($nonCompliant.Count / $evaluated.Count) * 100, 1) - $testResult = $percentage -le $MaxNonCompliantPercentage + $testResult = $percentage -le $MaximumNonCompliantPercentage $counts = [ordered]@{ 'Compliant' = @($devices | Where-Object { $_.ComplianceState -eq 'compliant' }).Count @@ -108,7 +108,7 @@ } $testResultMarkdown = "Evaluated $($evaluated.Count) of $($devices.Count) managed device(s). " - $testResultMarkdown += "**$($nonCompliant.Count)** ($percentage%) are non-compliant; the threshold is $MaxNonCompliantPercentage%.`n`n" + $testResultMarkdown += "**$($nonCompliant.Count)** ($percentage%) are non-compliant; the threshold is $MaximumNonCompliantPercentage%.`n`n" $testResultMarkdown += "| Compliance state | Devices |`n" $testResultMarkdown += "| --- | --- |`n" foreach ($state in $counts.Keys) { From d0e2841b1a3c9a08b3229464ef3580f0b49598bd Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Wed, 11 Nov 2026 11:48:12 -0400 Subject: [PATCH 09/13] chore(website): regenerate the test builder data for the new parameter #2758 added test parameters to website/src/data/test-builder.json, so a branch that declares one has to regenerate it with build/website/Update-MtTestBuilderData.ps1. TestBuilderData.Tests.ps1 fails otherwise. --- website/src/data/test-builder.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/src/data/test-builder.json b/website/src/data/test-builder.json index 2b025d35ea..d21e429196 100644 --- a/website/src/data/test-builder.json +++ b/website/src/data/test-builder.json @@ -18464,6 +18464,11 @@ "type": "int", "tests": 4 }, + { + "name": "MaximumNonCompliantPercentage", + "type": "int", + "tests": 1 + }, { "name": "MaximumPasswordAgeDays", "type": "int", From 45a67a238b9c3043b5d2b20c7619fc349372f3a5 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:08:40 -0400 Subject: [PATCH 10/13] feat(intune): MT.1268 covers the settings catalog baselines MT.1268 only read the legacy baselines (deviceManagement/templates, templateType securityBaseline). A tenant whose baselines are the current settings catalog kind got "There is nothing in this tenant for this test to check" - measured on a lab tenant where the only baseline sat in Error on its device. That is not a silence, it is the opposite of the truth, and it is the blocker raised in review. Get-MtSecurityBaseline now also reads deviceManagement/configurationPolicies whose templateReference/templateFamily is 'baseline' (a documented member of deviceManagementConfigurationTemplateFamily), expanding assignments in the same request. Each entry carries a Kind, so callers can tell the two apart. The settings catalog baselines are reported, not judged. Graph publishes no per-device compliance summary for them through a documented API: configurationPolicies has no deviceStatuses navigation, and the one route that carries the state, the DeviceStatusesByConfigurationProfile export, documents its column names but not the meaning of their values. So an assigned one is listed by name with its assignment count and skipped as not applicable, and an unassigned one is left out, exactly as an undeployed template already is. Building a verdict on an undocumented encoding would be worse than saying the number is unavailable, and the silent pass it replaces was worse than both. The legacy path is untouched: same counts, same verdict, same skip. Measured: 28 of 28 in the unit tests, up from 24. The four new cases fail against the previous version of the two files and the other 24 still pass, so they bite. TestAttributes 171, AttributeReview 35, NativeTestAttributes 25, NativeTestLint 16, TestBuilderData 3, TestParameterNames 14, GraphEndpoint and the URL check green. Export-MtGoldenFixture.ps1 leaves the fixtures unchanged. --- .../intune/Get-MtSecurityBaseline.ps1 | 43 ++++++++- ...t-MtIntuneDeviceComplianceStatus.Tests.ps1 | 96 +++++++++++++++++++ tests/maester/intune/Test.MT.1268.md | 9 +- tests/maester/intune/Test.MT.1268.ps1 | 59 +++++++++--- 4 files changed, 189 insertions(+), 18 deletions(-) diff --git a/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 b/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 index 2ad3ad732d..7ca27bc039 100644 --- a/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 +++ b/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 @@ -4,10 +4,21 @@ Retrieves Intune security baselines with the device-state summary Intune reports for each. .DESCRIPTION - Lists the security baseline templates in the tenant (beta deviceManagement/templates, templateType - 'securityBaseline') and, for each, reads its device-state summary. It returns a normalized object per - baseline carrying the display name and the per-state device counts (secure, not secure, conflict, - error, unknown and not applicable), plus the total number of devices reporting against it. + Lists the security baselines in the tenant, of both kinds, and returns a normalized object per + baseline carrying a Kind and the display name. + + Kind 'Template' is a legacy baseline (beta deviceManagement/templates, templateType + 'securityBaseline'). For each, this reads its device-state summary and carries the per-state device + counts (secure, not secure, conflict, error, unknown and not applicable), plus the total number of + devices reporting against it. + + Kind 'SettingsCatalog' is a current baseline (beta deviceManagement/configurationPolicies whose + templateReference/templateFamily is 'baseline'). These carry an AssignmentCount and no device counts, + because Intune publishes no per-device compliance summary for them through a documented API: + configurationPolicies has no deviceStatuses navigation, and the only route is the + DeviceStatusesByConfigurationProfile export, whose column *values* are undocumented. The caller + reports those baselines rather than judging them. Without this family a tenant whose baselines are + all current ones reports that there is nothing to check, which is the opposite of the truth. The total is included because a baseline template that no device reports against is not deployed to anything, so it cannot have a compliance outcome. The caller uses the total to leave undeployed @@ -60,6 +71,7 @@ $notApplicableCount = [int]$summary.notApplicableCount $result.Add([pscustomobject]@{ + Kind = 'Template' Id = $template.id Name = $template.displayName SecureCount = $secureCount @@ -72,6 +84,29 @@ }) } + # The current baselines live in the settings catalog, under a templateReference whose templateFamily + # is 'baseline' (a documented member of deviceManagementConfigurationTemplateFamily). Assignments are + # expanded in the same request so that an unassigned baseline can be told from a deployed one without + # a call per policy. + $policies = @(Invoke-MtGraphRequest -ApiVersion beta -ErrorAction Stop ` + -RelativeUri "deviceManagement/configurationPolicies?`$filter=templateReference/templateFamily eq 'baseline'&`$expand=assignments") + + $usablePolicies = @($policies | Where-Object { $_ -and $_.id }) + if ($policies.Count -gt 0 -and $usablePolicies.Count -eq 0) { + Write-Verbose "Settings catalog baselines could not be read; returning null so the caller reports a skip." + return $null + } + + foreach ($policy in $usablePolicies) { + $result.Add([pscustomobject]@{ + Kind = 'SettingsCatalog' + Id = $policy.id + # configurationPolicies carries 'name', not 'displayName'. + Name = $policy.name + AssignmentCount = @($policy.assignments | Where-Object { $_ }).Count + }) + } + # -NoEnumerate keeps an empty list from collapsing to $null. Write-Output $result -NoEnumerate } diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index b916b21ff4..2043e6daf3 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -36,6 +36,7 @@ [int] $NotApplicable = 0 ) return [pscustomobject]@{ + Kind = 'Template' Id = [guid]::NewGuid().ToString() Name = $Name SecureCount = $Secure @@ -47,6 +48,20 @@ TotalDeviceCount = $Secure + $NotSecure + $Conflict + $ErrorDevices + $Unknown + $NotApplicable } } + + function Get-TestSettingsCatalogBaseline { + # The current kind of baseline: no device counts exist for it, only assignments. + param( + [string] $Name = 'Security Baseline for Windows 10 and later', + [int] $Assignments = 1 + ) + return [pscustomobject]@{ + Kind = 'SettingsCatalog' + Id = [guid]::NewGuid().ToString() + Name = $Name + AssignmentCount = $Assignments + } + } } BeforeEach { @@ -211,6 +226,21 @@ Test-MtIntuneSecurityBaselineStatus -Instance $instance | Should -BeFalse } + It 'reports a settings catalog baseline and skips it instead of judging it' { + # Intune publishes no per-device compliance summary for this kind through a documented API. + # The baseline must still appear by name, with its assignment count: the failure this + # replaces was the family reporting that there was nothing in the tenant to check while a + # settings catalog baseline sat in error on its device. + $instance = [pscustomobject]@{ Data = (Get-TestSettingsCatalogBaseline -Name 'Windows 26H2' -Assignments 2) } + + $null -eq (Test-MtIntuneSecurityBaselineStatus -Instance $instance) | Should -BeTrue + $script:SkippedBecause | Should -Be 'NotApplicable' + $script:TestResult | Should -Match 'Windows 26H2' + $script:TestResult | Should -Match 'assigned to 2 group' + # It must not claim a verdict it cannot have. + $script:TestResult | Should -Not -Match 'Well done' + } + It 'skips as NotApplicable when no device has an evaluated verdict' { # Assigned, but every device is still unknown or not applicable: nothing to judge. $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Unknown 10 -NotApplicable 3) } @@ -236,6 +266,23 @@ $script:SkippedBecause | Should -BeNullOrEmpty } + It 'emits assigned settings catalog baselines and leaves unassigned ones out' { + # No device count exists for this kind, so deployment is read from the assignments. + Mock -ModuleName Maester Get-MtSecurityBaseline { + return @( + (Get-TestSettingsCatalogBaseline -Name 'Assigned baseline' -Assignments 1), + (Get-TestSettingsCatalogBaseline -Name 'Unassigned baseline' -Assignments 0), + (Get-TestBaseline -Name 'Legacy deployed' -Secure 3) + ) + } + + $instances = @(Get-MtIntuneSecurityBaselineInstance) + $instances.Count | Should -Be 2 + $instances.Title | Should -Contain "Security baseline 'Assigned baseline' should report every device as secure." + $instances.Title | Should -Not -Contain "Security baseline 'Unassigned baseline' should report every device as secure." + $instances.Title | Should -Contain "Security baseline 'Legacy deployed' should report every device as secure." + } + It 'skips the family as NotAuthorized when the baselines cannot be read' { Mock -ModuleName Maester Get-MtSecurityBaseline { return $null } @@ -282,6 +329,9 @@ } -MockWith { return [pscustomobject]@{ id = 's1'; secureCount = 8; notSecureCount = 2; conflictCount = 1; errorCount = 0; unknownCount = 3; notApplicableCount = 1 } } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @() } InModuleScope Maester { $result = Get-MtSecurityBaseline @@ -293,6 +343,46 @@ } } + It 'returns the settings catalog baselines with their assignment count' { + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'deviceManagement/templates' + } -MockWith { return @() } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { + # configurationPolicies carries 'name', not 'displayName'. + return @( + [pscustomobject]@{ id = 'pol-1'; name = 'Windows 26H2'; assignments = @([pscustomobject]@{ id = 'a1' }, [pscustomobject]@{ id = 'a2' }) }, + [pscustomobject]@{ id = 'pol-2'; name = 'Microsoft Edge'; assignments = @() } + ) + } + + InModuleScope Maester { + $result = Get-MtSecurityBaseline + $result.Count | Should -Be 2 + $result[0].Kind | Should -Be 'SettingsCatalog' + $result[0].Name | Should -Be 'Windows 26H2' + $result[0].AssignmentCount | Should -Be 2 + $result[1].AssignmentCount | Should -Be 0 + } + } + + It 'returns null when the settings catalog request yields elements without an id' { + # Same reasoning as the templates read: a failed call collects as a single empty element, + # and treating that as "this tenant has no current baselines" would hide a permission + # problem behind a clean result. + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -eq 'deviceManagement/templates' + } -MockWith { return @() } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @($null) } + + InModuleScope Maester { + $null -eq (Get-MtSecurityBaseline) | Should -BeTrue + } + } + It 'returns null when the templates request yields elements without an id' { Mock -ModuleName Maester Invoke-MtGraphRequest { return @($null) } @@ -305,6 +395,9 @@ Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { $RelativeUri -eq 'deviceManagement/templates' } -MockWith { return @() } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @() } InModuleScope Maester { $result = Get-MtSecurityBaseline @@ -325,6 +418,9 @@ # Only a secure count is present; everything else is absent. return [pscustomobject]@{ id = 's1'; secureCount = 4 } } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @() } InModuleScope Maester { $result = Get-MtSecurityBaseline diff --git a/tests/maester/intune/Test.MT.1268.md b/tests/maester/intune/Test.MT.1268.md index 358f61c2ed..90d30f5b38 100644 --- a/tests/maester/intune/Test.MT.1268.md +++ b/tests/maester/intune/Test.MT.1268.md @@ -2,9 +2,13 @@ Ensure devices **assigned a security baseline** comply with it. A security baseline is Microsoft's recommended set of hardening settings for a product (Windows, Microsoft Edge, Microsoft Defender for Endpoint and others). Assigning one is only half the job: a device can be assigned a baseline and still deviate from it, because a setting conflicts with another policy, because the device has not applied it, or because enforcement errored. Intune reports that outcome per baseline, and this check surfaces it. -This test runs **once per assigned security baseline** — a baseline that reports against at least one device. For each, Intune summarises its devices as secure, not secure, in conflict, in error, unknown or not applicable. The baseline **passes** when every device Intune has evaluated against it is secure, and **fails** when any device is not secure, in conflict, or in error. +This test runs **once per assigned security baseline**, of either kind. -A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is **skipped as not applicable**. A tenant with no assigned baselines is skipped too: there is nothing to report on, and that is never a pass. +**Legacy baselines** (the security baseline templates) report a device-state summary. The baseline **passes** when every device Intune has evaluated against it is secure, and **fails** when any device is not secure, in conflict, or in error. A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is **skipped as not applicable**. + +**Settings catalog baselines** — the kind the admin center creates today — are listed with their assignment count and **skipped as not applicable** rather than judged. Intune publishes no per-device compliance summary for them through a documented API: the `configurationPolicies` resource has no `deviceStatuses` navigation, and the one route that carries the state, the `DeviceStatusesByConfigurationProfile` export, documents its column names but not the meaning of their values. Reporting the baseline and saying the number is unavailable is honest; deciding a tenant's posture on an undocumented encoding is not, and passing it silently would be worse than both. To see their state, open the baseline in the admin center. + +A tenant with no assigned baselines of either kind is skipped: there is nothing to report on, and that is never a pass. #### Remediation action @@ -18,6 +22,7 @@ A baseline that is assigned but has no evaluated device yet (every device still - [Microsoft Intune admin center - Security baselines](https://intune.microsoft.com/#view/Microsoft_Intune_Workflows/SecurityManagementMenu/~/securityBaselines) - [Microsoft Learn - Use security baselines to configure Windows devices in Intune](https://learn.microsoft.com/intune/intune-service/protect/security-baselines) - [Microsoft Learn - Monitor security baselines and profiles](https://learn.microsoft.com/intune/intune-service/protect/security-baselines-monitor) +- [Microsoft Learn - Intune reports available using Graph APIs](https://learn.microsoft.com/intune/device-management/reports/ref-graph-available-reports#devicestatusesbyconfigurationprofile) %TestResult% diff --git a/tests/maester/intune/Test.MT.1268.ps1 b/tests/maester/intune/Test.MT.1268.ps1 index d4fd34101e..948381fa77 100644 --- a/tests/maester/intune/Test.MT.1268.ps1 +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -4,10 +4,15 @@ Returns one MT.1268 instance per assigned Intune security baseline. .DESCRIPTION - Instance source of the MT.1268 family. The suffix is the security baseline's template ID - (MT.1268.) and the title names the baseline. Only baselines that are actually deployed to - devices are emitted: a baseline template with no reporting device is not an assigned baseline and must - not surface as a passing result. + Instance source of the MT.1268 family. The suffix is the security baseline's ID and the title names + the baseline. Only baselines that are actually deployed are emitted: a baseline nothing has been + given is not an assigned baseline and must not surface as a passing result. + + Both kinds of baseline are emitted. A legacy template counts as deployed when at least one device + reports against it. A settings catalog baseline counts as deployed when it has at least one + assignment, since Intune exposes no device count for it; the check then reports it rather than + judging it. Leaving that kind out is what made a tenant whose baselines are all current ones report + that there was nothing here to check. When the baselines cannot be read at all (typically a 403 from Intune RBAC) the whole family is skipped rather than reported, because Add-MtTestResultDetail -SkippedBecause in an instance source @@ -40,9 +45,16 @@ } foreach ($baseline in $baselines) { - # Only baselines reporting against at least one device. An undeployed template has no outcome to - # judge, so leaving it out keeps it from surfacing as a (false) passing baseline. - if ($baseline.TotalDeviceCount -le 0) { continue } + if ($baseline.Kind -eq 'SettingsCatalog') { + # No device count exists for this kind, so deployment is read from the assignments. An + # unassigned baseline is left out for the same reason an undeployed template is. + if ([int]$baseline.AssignmentCount -le 0) { continue } + } else { + # Only baselines reporting against at least one device. An undeployed template has no outcome + # to judge, so leaving it out keeps it from surfacing as a (false) passing baseline. + if ($baseline.TotalDeviceCount -le 0) { continue } + } + [pscustomobject]@{ Id = $baseline.Id Title = "Security baseline '$($baseline.Name)' should report every device as secure." @@ -61,10 +73,20 @@ function Test-MtIntuneSecurityBaselineStatus { Intune reports for each assigned security baseline: whether the devices the baseline is deployed to actually match it. - It runs once per assigned security baseline (deviceManagement/templates of type securityBaseline that - report against at least one device). For each, Intune summarises its devices as secure, not secure, - in conflict, in error, unknown or not applicable. The baseline passes when every device Intune has - evaluated against it is secure, and fails when any device is not secure, in conflict, or in error. + It runs once per assigned security baseline, of either kind. + + For a legacy baseline (deviceManagement/templates of type securityBaseline that reports against at + least one device) Intune summarises its devices as secure, not secure, in conflict, in error, unknown + or not applicable. The baseline passes when every device Intune has evaluated against it is secure, + and fails when any device is not secure, in conflict, or in error. + + For a settings catalog baseline there is no such summary to read, so the baseline is reported and + skipped as not applicable rather than judged. Graph publishes no per-device state for + configurationPolicies - the resource has no deviceStatuses navigation, and the one route that carries + it, the DeviceStatusesByConfigurationProfile export, documents its column names but not the meaning of + their values. Deciding a tenant's security posture on an undocumented encoding is worse than saying + plainly that the number is not available, and a silent pass would be worse than both: on a tenant + whose only baseline sat in error, this family reported that there was nothing to check. A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is skipped as not applicable: a baseline nothing has reported a secure-or-not verdict on @@ -93,7 +115,8 @@ function Test-MtIntuneSecurityBaselineStatus { License = 'INTUNE_A', Lifecycle = 'Preview', InstanceSource = 'Get-MtIntuneSecurityBaselineInstance', - Author = 'earbona23' + Author = 'earbona23', + Contributor = ('julien-ly') )] [CmdletBinding()] [OutputType([bool])] @@ -103,6 +126,18 @@ function Test-MtIntuneSecurityBaselineStatus { ) $baseline = $Instance.Data + + if ($baseline.Kind -eq 'SettingsCatalog') { + $assignmentCount = [int]$baseline.AssignmentCount + $markdown = "Security baseline **$($baseline.Name)** is a settings catalog baseline, assigned to $assignmentCount group(s) or filter(s).`n`n" + $markdown += "Intune publishes no per-device compliance summary for a settings catalog baseline through a documented API, " + $markdown += "so this test reports the baseline rather than giving it a verdict. " + $markdown += "Check its device status in the Intune admin center under **Devices** > **Configuration**, or export " + $markdown += "[DeviceStatusesByConfigurationProfile](https://learn.microsoft.com/intune/device-management/reports/ref-graph-available-reports#devicestatusesbyconfigurationprofile)." + Add-MtTestResultDetail -Result $markdown -SkippedBecause NotApplicable + return $null + } + $secureCount = [int]$baseline.SecureCount $notSecureCount = [int]$baseline.NotSecureCount $conflictCount = [int]$baseline.ConflictCount From 54a95d4bfade8bd2a9a86bd67ecd33ffdeea7d41 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:46:33 -0400 Subject: [PATCH 11/13] fix(intune): escape the baseline name MT.1268 puts in its result A security baseline is named by a tenant admin and the name lands in the test result, which the report renders with gfm. Both branches interpolated it raw, so a baseline named '[Sign in again](https://phish.example)' rendered as a clickable link in the report, and a '|' broke the table. Get-MtSafeMarkdown is the helper the repository already uses for exactly this, in 28 places. Covered by a case that fails without the escape and passes with it, on both the legacy and the settings catalog path. 29 of 29. The instance Title still carries the name raw. That is the convention the other instance sources follow today - MT.1024, MT.1033, MT.1034 and MT.1059 all interpolate a tenant value into their Title - so changing it here alone would make this check the odd one out. It belongs with #2711 as a class, not buried in this pull request. --- .../Test-MtIntuneDeviceComplianceStatus.Tests.ps1 | 13 +++++++++++++ tests/maester/intune/Test.MT.1268.ps1 | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index 2043e6daf3..bde14263c7 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -241,6 +241,19 @@ $script:TestResult | Should -Not -Match 'Well done' } + It 'escapes a baseline name that carries markdown' { + # A baseline name is written by a tenant admin and lands in the report. Without escaping, + # a name like the one below renders as a clickable link in the result. + $hostil = '[Sign in again](https://phish.example)' + $settingsCatalog = [pscustomobject]@{ Data = (Get-TestSettingsCatalogBaseline -Name $hostil) } + $null -eq (Test-MtIntuneSecurityBaselineStatus -Instance $settingsCatalog) | Should -BeTrue + $script:TestResult | Should -Match '\\\[Sign in again' + + $legacy = [pscustomobject]@{ Data = (Get-TestBaseline -Name $hostil -Secure 3) } + Test-MtIntuneSecurityBaselineStatus -Instance $legacy | Should -BeTrue + $script:TestResult | Should -Match '\\\[Sign in again' + } + It 'skips as NotApplicable when no device has an evaluated verdict' { # Assigned, but every device is still unknown or not applicable: nothing to judge. $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Unknown 10 -NotApplicable 3) } diff --git a/tests/maester/intune/Test.MT.1268.ps1 b/tests/maester/intune/Test.MT.1268.ps1 index 948381fa77..11d93dcb89 100644 --- a/tests/maester/intune/Test.MT.1268.ps1 +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -129,7 +129,7 @@ function Test-MtIntuneSecurityBaselineStatus { if ($baseline.Kind -eq 'SettingsCatalog') { $assignmentCount = [int]$baseline.AssignmentCount - $markdown = "Security baseline **$($baseline.Name)** is a settings catalog baseline, assigned to $assignmentCount group(s) or filter(s).`n`n" + $markdown = "Security baseline **$(Get-MtSafeMarkdown $baseline.Name)** is a settings catalog baseline, assigned to $assignmentCount group(s) or filter(s).`n`n" $markdown += "Intune publishes no per-device compliance summary for a settings catalog baseline through a documented API, " $markdown += "so this test reports the baseline rather than giving it a verdict. " $markdown += "Check its device status in the Intune admin center under **Devices** > **Configuration**, or export " @@ -156,7 +156,7 @@ function Test-MtIntuneSecurityBaselineStatus { $deviatingCount = $notSecureCount + $conflictCount + $errorCount $testResult = $deviatingCount -eq 0 - $testResultMarkdown = "Security baseline **$($baseline.Name)** is reporting against $($baseline.TotalDeviceCount) device(s).`n`n" + $testResultMarkdown = "Security baseline **$(Get-MtSafeMarkdown $baseline.Name)** is reporting against $($baseline.TotalDeviceCount) device(s).`n`n" $testResultMarkdown += "| Device state | Devices |`n" $testResultMarkdown += "| --- | --- |`n" $testResultMarkdown += "| Secure | $secureCount |`n" From 124ddd10feef321d646745c6a0ef606440e2c83f Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:39:33 -0400 Subject: [PATCH 12/13] fix(intune): MT.1268 states why it skips instead of saying it does not apply NotApplicable makes the engine write "This test does not apply to this tenant." into ReasonDetail. Next to a result that says the baseline is assigned, that is the opposite of the detail: on a lab tenant the 26H2 baseline sat in Error on its device while the reason column said the test did not apply. Both skips now carry their own reason, which is what the cmdlet's SkippedCustomReason is for and what 153 other files in the repository do. The settings catalog skip says that Intune publishes no per-device state for that kind of baseline; the no-verdict skip says the baseline is assigned but nothing has reported yet. Reported by julien-ly, measured on a lab tenant with two settings catalog baselines assigned. --- tests/maester/intune/Test.MT.1268.md | 4 ++-- tests/maester/intune/Test.MT.1268.ps1 | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/maester/intune/Test.MT.1268.md b/tests/maester/intune/Test.MT.1268.md index 90d30f5b38..7906475f63 100644 --- a/tests/maester/intune/Test.MT.1268.md +++ b/tests/maester/intune/Test.MT.1268.md @@ -4,9 +4,9 @@ A security baseline is Microsoft's recommended set of hardening settings for a p This test runs **once per assigned security baseline**, of either kind. -**Legacy baselines** (the security baseline templates) report a device-state summary. The baseline **passes** when every device Intune has evaluated against it is secure, and **fails** when any device is not secure, in conflict, or in error. A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is **skipped as not applicable**. +**Legacy baselines** (the security baseline templates) report a device-state summary. The baseline **passes** when every device Intune has evaluated against it is secure, and **fails** when any device is not secure, in conflict, or in error. A baseline that is assigned but has no evaluated device yet (every device still unknown or not applicable) is **skipped**, with that stated as the reason. -**Settings catalog baselines** — the kind the admin center creates today — are listed with their assignment count and **skipped as not applicable** rather than judged. Intune publishes no per-device compliance summary for them through a documented API: the `configurationPolicies` resource has no `deviceStatuses` navigation, and the one route that carries the state, the `DeviceStatusesByConfigurationProfile` export, documents its column names but not the meaning of their values. Reporting the baseline and saying the number is unavailable is honest; deciding a tenant's posture on an undocumented encoding is not, and passing it silently would be worse than both. To see their state, open the baseline in the admin center. +**Settings catalog baselines** — the kind the admin center creates today — are listed with their assignment count and **skipped**, with the missing per-device state stated as the reason, rather than judged. Intune publishes no per-device compliance summary for them through a documented API: the `configurationPolicies` resource has no `deviceStatuses` navigation, and the one route that carries the state, the `DeviceStatusesByConfigurationProfile` export, documents its column names but not the meaning of their values. Reporting the baseline and saying the number is unavailable is honest; deciding a tenant's posture on an undocumented encoding is not, and passing it silently would be worse than both. To see their state, open the baseline in the admin center. A tenant with no assigned baselines of either kind is skipped: there is nothing to report on, and that is never a pass. diff --git a/tests/maester/intune/Test.MT.1268.ps1 b/tests/maester/intune/Test.MT.1268.ps1 index 11d93dcb89..6374d69d07 100644 --- a/tests/maester/intune/Test.MT.1268.ps1 +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -81,7 +81,9 @@ function Test-MtIntuneSecurityBaselineStatus { and fails when any device is not secure, in conflict, or in error. For a settings catalog baseline there is no such summary to read, so the baseline is reported and - skipped as not applicable rather than judged. Graph publishes no per-device state for + skipped with a reason that names the limitation rather than judged. The engine's NotApplicable text + ("This test does not apply to this tenant.") said the opposite of the detail next to it, which states + that the baseline is assigned. Graph publishes no per-device state for configurationPolicies - the resource has no deviceStatuses navigation, and the one route that carries it, the DeviceStatusesByConfigurationProfile export, documents its column names but not the meaning of their values. Deciding a tenant's security posture on an undocumented encoding is worse than saying @@ -89,8 +91,8 @@ function Test-MtIntuneSecurityBaselineStatus { whose only baseline sat in error, this family reported that there was nothing to check. A baseline that is assigned but has no evaluated device yet (every device still unknown or not - applicable) is skipped as not applicable: a baseline nothing has reported a secure-or-not verdict on - is not a compliant baseline. + applicable) is skipped with that as its stated reason: a baseline nothing has reported a + secure-or-not verdict on is not a compliant baseline. .EXAMPLE Test-MtIntuneSecurityBaselineStatus @@ -134,7 +136,7 @@ function Test-MtIntuneSecurityBaselineStatus { $markdown += "so this test reports the baseline rather than giving it a verdict. " $markdown += "Check its device status in the Intune admin center under **Devices** > **Configuration**, or export " $markdown += "[DeviceStatusesByConfigurationProfile](https://learn.microsoft.com/intune/device-management/reports/ref-graph-available-reports#devicestatusesbyconfigurationprofile)." - Add-MtTestResultDetail -Result $markdown -SkippedBecause NotApplicable + Add-MtTestResultDetail -Result $markdown -SkippedBecause Custom -SkippedCustomReason 'Intune publishes no per-device state for a settings catalog baseline, so this baseline is reported rather than judged.' return $null } @@ -149,7 +151,7 @@ function Test-MtIntuneSecurityBaselineStatus { if ($evaluatedCount -le 0) { # Assigned, but no device has reported a secure or not-secure verdict yet. There is no outcome to # judge, so skip rather than pass. - Add-MtTestResultDetail -SkippedBecause NotApplicable + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason 'This baseline is assigned, but no device has reported a secure or not-secure verdict yet.' return $null } From 8734a3e69a80f6b5cd1a96ab5ba08635c067c627 Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:14:14 -0400 Subject: [PATCH 13/13] test(intune): the MT.1268 skips assert their own reason The change to Custom left two cases asserting NotApplicable, and they failed. I did not run them before pushing: a search for a file named after the check came back empty and I read that as there being no tests, instead of searching for the function. The file is named after MT.1267. Both now assert the reason as well as the skip, which is the part that was wrong in the first place, and a third case holds the two reasons apart: a settings catalog baseline and a legacy one with no verdict yet are different situations and must not collapse into one sentence. 30 of 30 on Pester 5.7.1. --- ...t-MtIntuneDeviceComplianceStatus.Tests.ps1 | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 index bde14263c7..1258096368 100644 --- a/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -67,13 +67,15 @@ BeforeEach { $script:TestResult = $null $script:SkippedBecause = $null + $script:SkippedCustomReason = $null Mock -ModuleName Maester Get-MtLicenseInformation { return $true } Mock -ModuleName Maester Add-MtTestResultDetail { - param($Result, $SkippedBecause) + param($Result, $SkippedBecause, $SkippedCustomReason) $script:TestResult = $Result $script:SkippedBecause = $SkippedBecause + $script:SkippedCustomReason = $SkippedCustomReason } } @@ -234,7 +236,10 @@ $instance = [pscustomobject]@{ Data = (Get-TestSettingsCatalogBaseline -Name 'Windows 26H2' -Assignments 2) } $null -eq (Test-MtIntuneSecurityBaselineStatus -Instance $instance) | Should -BeTrue - $script:SkippedBecause | Should -Be 'NotApplicable' + # Not NotApplicable: the engine writes "This test does not apply to this tenant." for that, + # which contradicts a result stating the baseline is assigned. + $script:SkippedBecause | Should -Be 'Custom' + $script:SkippedCustomReason | Should -Match 'no per-device state' $script:TestResult | Should -Match 'Windows 26H2' $script:TestResult | Should -Match 'assigned to 2 group' # It must not claim a verdict it cannot have. @@ -254,12 +259,27 @@ $script:TestResult | Should -Match '\\\[Sign in again' } - It 'skips as NotApplicable when no device has an evaluated verdict' { - # Assigned, but every device is still unknown or not applicable: nothing to judge. + It 'skips with its own reason when no device has an evaluated verdict' { + # Assigned, but every device is still unknown or not applicable: nothing to judge. The + # reason has to say that, because "does not apply to this tenant" is the opposite of a + # baseline the tenant has assigned. $instance = [pscustomobject]@{ Data = (Get-TestBaseline -Unknown 10 -NotApplicable 3) } $null -eq (Test-MtIntuneSecurityBaselineStatus -Instance $instance) | Should -BeTrue - $script:SkippedBecause | Should -Be 'NotApplicable' + $script:SkippedBecause | Should -Be 'Custom' + $script:SkippedCustomReason | Should -Match 'no device has reported' + } + + It 'keeps the two baseline skips apart' { + # A settings catalog baseline and a legacy one with no verdict are different situations and + # must not collapse into one reason. + $null = Test-MtIntuneSecurityBaselineStatus -Instance ([pscustomobject]@{ Data = (Get-TestSettingsCatalogBaseline -Name 'A' -Assignments 1) }) + $catalogo = $script:SkippedCustomReason + + $null = Test-MtIntuneSecurityBaselineStatus -Instance ([pscustomobject]@{ Data = (Get-TestBaseline -Unknown 4) }) + $sinVeredicto = $script:SkippedCustomReason + + $catalogo | Should -Not -Be $sinVeredicto } }