Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
$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 <State> 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 <Heartbeat>' -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 '*No heartbeat in the last 48 hours*'
}

It 'Preserves the existing heartbeat boundary at <Hours> 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*'
}
}
10 changes: 8 additions & 2 deletions tests/maester/intune/Test.MT.1098.md
Original file line number Diff line number Diff line change
@@ -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 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.

#### 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.

<!--- Results --->
%TestResult%
%TestResult%
43 changes: 37 additions & 6 deletions tests/maester/intune/Test.MT.1098.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Service = 'Graph',
License = 'INTUNE_A',
Author = 'nicolonsky',
Contributor = 'Mynster9361'
Contributor = ('Mynster9361', 'FiraSenax')
)]
[CmdletBinding()]
[OutputType([bool])]
Expand Down Expand Up @@ -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
# 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 += 'No heartbeat in the last 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)
}

Expand Down
Loading