From ef238a6e43d15ce202f6d3569e8446fd3142b371 Mon Sep 17 00:00:00 2001 From: Sven Frank <82213858+FiraSenax@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:41:25 +0100 Subject: [PATCH 1/3] fix(intune): explain unhealthy MTD connector states --- ...-MtMobileThreatDefenseConnectors.Tests.ps1 | 165 ++++++++++++++++++ tests/maester/intune/Test.MT.1098.md | 10 +- tests/maester/intune/Test.MT.1098.ps1 | 43 ++++- 3 files changed, 210 insertions(+), 8 deletions(-) create mode 100644 powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 diff --git a/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 new file mode 100644 index 0000000000..dd02d56995 --- /dev/null +++ b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 @@ -0,0 +1,165 @@ +BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Test-MtMobileThreatDefenseConnectors +} + +Describe 'Test-MtMobileThreatDefenseConnectors' { + BeforeEach { + $script:Result = $null + $script:Connector = [pscustomobject]@{ + id = 'c2b688fe-48c0-464b-a89c-67041aa8fcb2' + partnerState = 'enabled' + lastHeartbeatDateTime = '2026-11-08T10:00:00Z' + } + Mock -ModuleName Maester Get-Date { [datetime]'2026-11-08T12:00:00Z' } + Mock -ModuleName Maester Invoke-MtGraphRequest { $script:Connector } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $SkippedBecause, $SkippedCustomReason) + $script:Result = $Result + } + } + + It 'Passes for an enabled connector with a recent heartbeat' { + Test-MtMobileThreatDefenseConnectors | Should -BeTrue + $script:Result | Should -BeLike '*Enabled with a recent heartbeat*' + Should -Invoke -ModuleName Maester Invoke-MtGraphRequest -Times 1 -Exactly -ParameterFilter { + $RelativeUri -eq 'deviceManagement/mobileThreatDefenseConnectors' -and $ApiVersion -eq 'beta' + } + } + + It 'Explains without changing it to a pass' -ForEach @( + @{ State = 'notSetUp'; Reason = '*Setup is incomplete*device threat messages are blocked*' } + @{ State = 'unavailable'; Reason = '*deprovisioned*' } + @{ State = 'available'; Reason = '*Turn on a platform toggle*' } + @{ State = 'unresponsive'; Reason = '*unresponsive*Intune ignores*' } + @{ State = 'error'; Reason = '*reported an error*' } + @{ State = 'unknownFutureValue'; Reason = '*Unrecognized connector state*' } + @{ State = 'newPartnerState'; Reason = '*Unrecognized connector state*' } + ) { + $script:Connector.partnerState = $State + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -BeLike $Reason + } + + It 'Explains a missing heartbeat for ' -ForEach @( + @{ Heartbeat = '0001-01-01T00:00:00Z' } + @{ Heartbeat = $null } + ) { + $script:Connector.lastHeartbeatDateTime = $Heartbeat + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -BeLike '*Never received*' + $script:Result | Should -Not -BeLike '*0001-01-01*' + } + + It 'Reports both incomplete setup and a missing heartbeat' { + $script:Connector.partnerState = 'notSetUp' + $script:Connector.lastHeartbeatDateTime = '0001-01-01T00:00:00Z' + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -BeLike '*Setup is incomplete*' + $script:Result | Should -BeLike '*No heartbeat has been received*' + } + + It 'Explains a stale heartbeat' { + $script:Connector.lastHeartbeatDateTime = '2026-11-05T12:00:00Z' + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -BeLike '*Heartbeat is outside the test*' + } + + It 'Preserves the existing heartbeat boundary at hours' -ForEach @( + @{ Hours = 47; Expected = $true } + @{ Hours = 48; Expected = $false } + ) { + $script:Connector.lastHeartbeatDateTime = ([datetime]'2026-11-08T12:00:00Z').AddHours(-$Hours) + + Test-MtMobileThreatDefenseConnectors | Should -Be $Expected + } + + It 'Fails when one of several connectors is unhealthy and reports both' { + Mock -ModuleName Maester Invoke-MtGraphRequest { + $script:Connector + [pscustomobject]@{ + id = 'fc780465-2017-40d4-a0c5-307022471b92' + partnerState = 'notSetUp' + lastHeartbeatDateTime = '0001-01-01T00:00:00Z' + } + } + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -BeLike '*Windows Security Center*' + $script:Result | Should -BeLike '*Microsoft Defender for Endpoint*' + } + + It 'Escapes unknown connector IDs and states in the report table' { + $script:Connector.id = '[link](https://example.test) | extra' + $script:Connector.partnerState = '**unknown** | extra' + + Test-MtMobileThreatDefenseConnectors | Should -BeFalse + $script:Result | Should -Not -BeLike '*[[]link](https://example.test)*' + $script:Result | Should -Not -BeLike '* | extra*' + $script:Result | Should -BeLike '*Unrecognized connector state*' + } + + It 'Keeps the no-connectors skip' { + Mock -ModuleName Maester Invoke-MtGraphRequest { @() } + + Test-MtMobileThreatDefenseConnectors | Should -BeNullOrEmpty + Should -Invoke -ModuleName Maester Add-MtTestResultDetail -Times 1 -Exactly -ParameterFilter { + $SkippedBecause -eq 'Custom' -and "$SkippedCustomReason" -like '*No Mobile Threat Defense Connectors found*' + } + } + + It 'Propagates Graph errors' { + Mock -ModuleName Maester Invoke-MtGraphRequest { throw 'Graph unavailable' } + + { Test-MtMobileThreatDefenseConnectors } | Should -Throw '*Graph unavailable*' + } +} + +Describe 'MT.1098 native engine results' { + BeforeEach { + Mock -ModuleName Maester Get-MgContext { $null } + $script:config = [pscustomobject]@{ + Environment = [pscustomobject]@{ + Services = [pscustomobject]@{ Graph = $true } + Licenses = @('INTUNE_A') + } + } + } + + It 'Records incomplete setup as Failed with actionable result details' { + Mock -ModuleName Maester Invoke-MtGraphRequest { + [pscustomobject]@{ + id = 'c2b688fe-48c0-464b-a89c-67041aa8fcb2' + partnerState = 'notSetUp' + lastHeartbeatDateTime = '0001-01-01T00:00:00Z' + } + } + + $rows = @(Invoke-MtTest -Id 'MT.1098' -Config $script:config) + $rows | Should -HaveCount 1 + $rows[0].Result | Should -Be 'Failed' + $rows[0].ResultDetail.TestResult | Should -BeLike '*Setup is incomplete*' + $rows[0].ResultDetail.TestResult | Should -BeLike '*Never received*' + } + + It 'Records the no-connectors case as Skipped through the engine' { + Mock -ModuleName Maester Invoke-MtGraphRequest { @() } + + $row = Invoke-MtTest -Id 'MT.1098' -Config $script:config + $row.Result | Should -Be 'Skipped' + $row.ReasonDetail | Should -BeLike '*No Mobile Threat Defense Connectors found*' + } + + It 'Records unreadable connector data as Error through the engine' { + Mock -ModuleName Maester Invoke-MtGraphRequest { throw 'Graph unavailable' } + + $row = Invoke-MtTest -Id 'MT.1098' -Config $script:config + $row.Result | Should -Be 'Error' + $row.ReasonDetail | Should -BeLike '*Graph unavailable*' + } +} diff --git a/tests/maester/intune/Test.MT.1098.md b/tests/maester/intune/Test.MT.1098.md index 4cb264106d..1b4beb648c 100644 --- a/tests/maester/intune/Test.MT.1098.md +++ b/tests/maester/intune/Test.MT.1098.md @@ -1,14 +1,20 @@ This test verifies the health of Intune Mobile Threat Defense Connectors, including Microsoft Defender for Endpoint. +Each connector must be enabled and have a heartbeat less than 48 hours old (the existing check allows at most one completed day). The result table explains unhealthy states and reports a missing or year-1 heartbeat as **Never received**. + +A connector in `notSetUp` has not completed setup and blocks device threat messages. A connector in `available` has completed setup but needs a platform toggle enabled. Neither state satisfies this health check. An `unresponsive` connector needs attention because Intune ignores its compliance state once the configured unresponsiveness threshold is reached. + #### Remediation action +Review each connector's **Reason** in the result table. Complete setup and required permissions for a `notSetUp` connector, enable the relevant platform for an `available` connector, or remove a connector that is no longer needed. For a missing or stale heartbeat, verify the partner service and its connectivity to Intune. + For Microsoft Defender for Endpoint visit the [Microsoft Defender for Endpoint Tenant Settings](https://intune.microsoft.com/#view/Microsoft_Intune_DeviceSettings/TenantAdminConnectorsMenu/~/windowsDefenderATP) and ensure that the connector is also enabled from the Microsoft Defender XDR Settings as part of the [Microsoft Intune connection](https://security.microsoft.com/securitysettings/endpoints/integration). Additional information: * [Integrate Microsoft Defender for Endpoint with Intune and Onboard Devices](https://learn.microsoft.com/intune/intune-service/protect/microsoft-defender-integrate) -* If you have a third party connector, consult your third party MTD solution. More information can be found on the [Mobile Threat Defense integration with Intune](https://learn.microsoft.com/intune/intune-service/protect/mobile-threat-defense#connector-status) learn page. +* If you have a third party connector, consult your third party MTD solution. More information can be found on the [Mobile Threat Defense integration with Intune](https://learn.microsoft.com/intune/device-security/mobile-threat-defense/overview#connector-status) learn page. -%TestResult% \ No newline at end of file +%TestResult% diff --git a/tests/maester/intune/Test.MT.1098.ps1 b/tests/maester/intune/Test.MT.1098.ps1 index b5ea75d74e..8f500f7f5a 100644 --- a/tests/maester/intune/Test.MT.1098.ps1 +++ b/tests/maester/intune/Test.MT.1098.ps1 @@ -28,7 +28,7 @@ Service = 'Graph', License = 'INTUNE_A', Author = 'nicolonsky', - Contributor = 'Mynster9361' + Contributor = ('Mynster9361', 'FiraSenax') )] [CmdletBinding()] [OutputType([bool])] @@ -65,21 +65,52 @@ } $testResultMarkdown = "Mobile Threat Defense Connector Status:`n" - $testResultMarkdown += "| Name | LastHeartbeatDateTime | PartnerState |`n" - $testResultMarkdown += "| --- | --- | --- |`n" + $testResultMarkdown += "| Name | LastHeartbeatDateTime | PartnerState | Reason |`n" + $testResultMarkdown += "| --- | --- | --- | --- |`n" $connectorStatus = foreach ($connector in $mobileThreatDefenseConnectors) { if ($mtdConnectorInformation.ContainsKey($connector.id)) { Write-Verbose ('Found {0} Connector.' -f $mtdConnectorInformation[$connector.id]) - $testResultMarkdown += "| $($mtdConnectorInformation[$connector.id]) | $($connector.lastHeartbeatDateTime) | $($connector.partnerState) |`n" + $connectorName = $mtdConnectorInformation[$connector.id] } else { Write-Verbose ('Found Unknown Third Party Mobile Threat Defense Connector: {0}' -f $connector.id) - $testResultMarkdown += "| $($connector.id) | $($connector.lastHeartbeatDateTime) | $($connector.partnerState) |`n" + $connectorName = $connector.id } $isConnected = $connector.partnerState -eq 'enabled' - $syncIsRecent = [System.Math]::Floor(((Get-Date) - [datetime]$connector.lastHeartbeatDateTime).TotalDays) -le 1 + $reasons = @(switch ($connector.partnerState) { + 'enabled' { break } + 'notSetUp' { 'Setup is incomplete; device threat messages are blocked. Complete setup in Intune and with the partner, or remove an unused connector.' } + 'unavailable' { 'The connector is deprovisioned; device threat messages are blocked. Ask the MTD partner to provision it again.' } + 'available' { 'Setup is complete. Turn on a platform toggle to enable the connector.' } + 'unresponsive' { 'The connector is unresponsive. After its configured unresponsiveness threshold, Intune ignores its compliance state. Check the partner service and connectivity.' } + 'error' { 'The connector reported an error. Check the partner service for the error details.' } + default { 'Unrecognized connector state. Review the connector in Intune and with the partner.' } + }) + + $heartbeat = if ($connector.lastHeartbeatDateTime) { [datetime]$connector.lastHeartbeatDateTime } else { [datetime]::MinValue } + if ($heartbeat.Year -eq 1) { + $heartbeatDisplay = 'Never received' + $syncIsRecent = $false + $reasons += 'No heartbeat has been received. Complete setup and verify that the partner can communicate with Intune.' + } else { + $heartbeatDisplay = [string]$connector.lastHeartbeatDateTime + # Keep the existing window: at most one completed day since the heartbeat (less than 48 hours). + $syncIsRecent = [System.Math]::Floor(((Get-Date) - $heartbeat).TotalDays) -le 1 + if (-not $syncIsRecent) { + $reasons += "Heartbeat is outside the test's existing window (less than 48 hours). Check the partner service and connectivity." + } + } + + if ($isConnected -and $syncIsRecent) { + $reasons = @('Enabled with a recent heartbeat.') + } + + $nameMarkdown = Get-MtSafeMarkdown -Text $connectorName + $heartbeatMarkdown = Get-MtSafeMarkdown -Text $heartbeatDisplay + $stateMarkdown = Get-MtSafeMarkdown -Text ([string]$connector.partnerState) + $testResultMarkdown += "| $nameMarkdown | $heartbeatMarkdown | $stateMarkdown | $($reasons -join ' ') |`n" Write-Output ($isConnected -and $syncIsRecent) } From 3134b71212aec4e7d7965c31cfadbbf55f385032 Mon Sep 17 00:00:00 2001 From: Sven Frank <82213858+FiraSenax@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:50:33 +0100 Subject: [PATCH 2/3] test(intune): remove unused connector mock parameters --- .../functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 index dd02d56995..f658d68d00 100644 --- a/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 +++ b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 @@ -15,7 +15,7 @@ Describe 'Test-MtMobileThreatDefenseConnectors' { Mock -ModuleName Maester Get-Date { [datetime]'2026-11-08T12:00:00Z' } Mock -ModuleName Maester Invoke-MtGraphRequest { $script:Connector } Mock -ModuleName Maester Add-MtTestResultDetail { - param($Result, $SkippedBecause, $SkippedCustomReason) + param($Result) $script:Result = $Result } } From f41e650c8930302ec48041b63cab2b47bf85617f Mon Sep 17 00:00:00 2001 From: Merill Fernando Date: Mon, 9 Nov 2026 19:34:39 +1100 Subject: [PATCH 3/3] fix(intune): say 'no heartbeat in the last 48 hours' in MT.1098 Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M6ZQ3XFATYYQTYJ0NQN6VJVT --- .../functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 | 2 +- tests/maester/intune/Test.MT.1098.md | 2 +- tests/maester/intune/Test.MT.1098.ps1 | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 index f658d68d00..78d7329bc1 100644 --- a/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 +++ b/powershell/tests/functions/Test-MtMobileThreatDefenseConnectors.Tests.ps1 @@ -67,7 +67,7 @@ Describe 'Test-MtMobileThreatDefenseConnectors' { $script:Connector.lastHeartbeatDateTime = '2026-11-05T12:00:00Z' Test-MtMobileThreatDefenseConnectors | Should -BeFalse - $script:Result | Should -BeLike '*Heartbeat is outside the test*' + $script:Result | Should -BeLike '*No heartbeat in the last 48 hours*' } It 'Preserves the existing heartbeat boundary at hours' -ForEach @( diff --git a/tests/maester/intune/Test.MT.1098.md b/tests/maester/intune/Test.MT.1098.md index 1b4beb648c..ae623ce5ff 100644 --- a/tests/maester/intune/Test.MT.1098.md +++ b/tests/maester/intune/Test.MT.1098.md @@ -1,6 +1,6 @@ This test verifies the health of Intune Mobile Threat Defense Connectors, including Microsoft Defender for Endpoint. -Each connector must be enabled and have a heartbeat less than 48 hours old (the existing check allows at most one completed day). The result table explains unhealthy states and reports a missing or year-1 heartbeat as **Never received**. +Each connector must be enabled and have a heartbeat in the last 48 hours. The result table explains unhealthy states and reports a missing or year-1 heartbeat as **Never received**. A connector in `notSetUp` has not completed setup and blocks device threat messages. A connector in `available` has completed setup but needs a platform toggle enabled. Neither state satisfies this health check. An `unresponsive` connector needs attention because Intune ignores its compliance state once the configured unresponsiveness threshold is reached. diff --git a/tests/maester/intune/Test.MT.1098.ps1 b/tests/maester/intune/Test.MT.1098.ps1 index 8f500f7f5a..bb8c2b8115 100644 --- a/tests/maester/intune/Test.MT.1098.ps1 +++ b/tests/maester/intune/Test.MT.1098.ps1 @@ -96,10 +96,10 @@ $reasons += 'No heartbeat has been received. Complete setup and verify that the partner can communicate with Intune.' } else { $heartbeatDisplay = [string]$connector.lastHeartbeatDateTime - # Keep the existing window: at most one completed day since the heartbeat (less than 48 hours). + # At most one completed day since the heartbeat, so less than 48 hours. $syncIsRecent = [System.Math]::Floor(((Get-Date) - $heartbeat).TotalDays) -le 1 if (-not $syncIsRecent) { - $reasons += "Heartbeat is outside the test's existing window (less than 48 hours). Check the partner service and connectivity." + $reasons += 'No heartbeat in the last 48 hours. Check the partner service and connectivity.' } }