Private/Test-DcXmlWithMpCmdRun.ps1

function Test-DcXmlWithMpCmdRun {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)][string]$XmlPath,
        [ValidateSet('Groups','Rules')][Parameter(Mandatory)][string]$Kind
    )

    $exe = Get-DefenderMpCmdRun
    if (-not $exe) {
        Write-Warning " MpCmdRun.exe not found - skipping engine-side validation of $XmlPath."
        return
    }
    $arg = if ($Kind -eq 'Groups') { '-Groups' } else { '-Rules' }
    $output = & $exe -DeviceControl -TestPolicyXml $XmlPath $arg 2>&1
    $exit = $LASTEXITCODE
    $output | ForEach-Object { Write-Verbose " $_" }
    if ($exit -ne 0) {
        throw "MpCmdRun -TestPolicyXml $arg returned $exit for $XmlPath - aborting before any registry writes."
    }
}