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..7ca27bc039 --- /dev/null +++ b/powershell/internal/services/intune/Get-MtSecurityBaseline.ps1 @@ -0,0 +1,112 @@ +function Get-MtSecurityBaseline { + <# + .SYNOPSIS + Retrieves Intune security baselines with the device-state summary Intune reports for each. + + .DESCRIPTION + 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 + 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]@{ + Kind = 'Template' + 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 + }) + } + + # 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/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json index ae970e7cfd..ec294d554b 100644 --- a/powershell/tests/fixtures/golden/selection.json +++ b/powershell/tests/fixtures/golden/selection.json @@ -1951,7 +1951,7 @@ "AD" ] }, - "SelectedCount": 609, + "SelectedCount": 611, "SelectedFamilies": [ "MT.1024", "MT.1059", @@ -2500,6 +2500,8 @@ "MT.1259", "MT.1260", "MT.1265", + "MT.1267", + "MT.1268", "ORCA.100", "ORCA.101", "ORCA.102", @@ -2581,7 +2583,7 @@ "AD" ] }, - "SelectedCount": 639, + "SelectedCount": 641, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -3162,6 +3164,8 @@ "MT.1259", "MT.1260", "MT.1265", + "MT.1267", + "MT.1268", "ORCA.100", "ORCA.101", "ORCA.102", @@ -4006,7 +4010,7 @@ "AD" ] }, - "SelectedCount": 595, + "SelectedCount": 597, "SelectedFamilies": [ "MT.1024", "MT.1033", @@ -4543,6 +4547,8 @@ "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 new file mode 100644 index 0000000000..1258096368 --- /dev/null +++ b/powershell/tests/functions/Test-MtIntuneDeviceComplianceStatus.Tests.ps1 @@ -0,0 +1,466 @@ +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]@{ + Kind = 'Template' + 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 + } + } + + 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 { + $script:TestResult = $null + $script:SkippedBecause = $null + $script:SkippedCustomReason = $null + + Mock -ModuleName Maester Get-MtLicenseInformation { return $true } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $SkippedBecause, $SkippedCustomReason) + + $script:TestResult = $Result + $script:SkippedBecause = $SkippedBecause + $script:SkippedCustomReason = $SkippedCustomReason + } + } + + 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')) + } + + 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 -MaximumNonCompliantPercentage 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.1268)' { + 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 '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 + # 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. + $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 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 '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 + } + } + + 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 @( + (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 '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 } + + $instances = @(Get-MtIntuneSecurityBaselineInstance) + $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.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' } + + { Get-MtIntuneSecurityBaselineInstance } | Should -Throw + $script:SkippedBecause | Should -BeNullOrEmpty + } + } + + 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 } + } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @() } + + 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 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) } + + 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 @() } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -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 } + } + Mock -ModuleName Maester Invoke-MtGraphRequest -ParameterFilter { + $RelativeUri -like 'deviceManagement/configurationPolicies*' + } -MockWith { return @() } + + 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.1267.md b/tests/maester/intune/Test.MT.1267.md new file mode 100644 index 0000000000..fb4883a478 --- /dev/null +++ b/tests/maester/intune/Test.MT.1267.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 `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. + +#### 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.1267.ps1 b/tests/maester/intune/Test.MT.1267.ps1 new file mode 100644 index 0000000000..11c1d016b1 --- /dev/null +++ b/tests/maester/intune/Test.MT.1267.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 -MaximumNonCompliantPercentage 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.1267', + Title = 'Non-compliant Intune managed devices should be below the configured threshold.', + Product = 'intune', + Feature = 'device-compliance', + Area = 'devices', + ResourceType = 'Device', + Severity = 'Medium', + UserImpact = 'Medium', + ImplementationCost = 'Medium', + Mitre = 'None', + Service = 'Graph', + License = 'INTUNE_A', + Lifecycle = 'Preview', + 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] $MaximumNonCompliantPercentage = 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 $MaximumNonCompliantPercentage + + $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 $MaximumNonCompliantPercentage%.`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.1268.md b/tests/maester/intune/Test.MT.1268.md new file mode 100644 index 0000000000..7906475f63 --- /dev/null +++ b/tests/maester/intune/Test.MT.1268.md @@ -0,0 +1,28 @@ +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**, 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**, with that stated as the reason. + +**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. + +#### 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) +- [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 new file mode 100644 index 0000000000..6374d69d07 --- /dev/null +++ b/tests/maester/intune/Test.MT.1268.ps1 @@ -0,0 +1,180 @@ +function Get-MtIntuneSecurityBaselineInstance { + <# + .SYNOPSIS + 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 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 + 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() + + # 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.1267 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 + } + + foreach ($baseline in $baselines) { + 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." + 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, 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 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 + 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 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 + + 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.1268', + 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', + Service = 'Graph', + License = 'INTUNE_A', + Lifecycle = 'Preview', + InstanceSource = 'Get-MtIntuneSecurityBaselineInstance', + Author = 'earbona23', + Contributor = ('julien-ly') + )] + [CmdletBinding()] + [OutputType([bool])] + param( + # The baseline to check, supplied by the engine. + $Instance + ) + + $baseline = $Instance.Data + + if ($baseline.Kind -eq 'SettingsCatalog') { + $assignmentCount = [int]$baseline.AssignmentCount + $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 " + $markdown += "[DeviceStatusesByConfigurationProfile](https://learn.microsoft.com/intune/device-management/reports/ref-graph-available-reports#devicestatusesbyconfigurationprofile)." + 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 + } + + $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 Custom -SkippedCustomReason 'This baseline is assigned, but no device has reported a secure or not-secure verdict yet.' + return $null + } + + $deviatingCount = $notSecureCount + $conflictCount + $errorCount + $testResult = $deviatingCount -eq 0 + + $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" + $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 +} 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",