Skip to content
Open
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,93 @@
# ============================================================================
# Eriteach Scripts
# Author: Robel (https://github.com/Thugney)
# Repository: https://github.com/Thugney/eriteach-scripts
# License: MIT
# ============================================================================

<#
.SYNOPSIS
Kontrollerer Microsoft Defender motor- og plattformversjon.

.DESCRIPTION
Intune Proactive Remediation detection script for Microsoft Defender
Antivirus version compliance. The script checks Microsoft Defender
Malware Protection Engine and Antimalware Platform versions using
Get-MpComputerStatus.

Exit 0 = compliant.
Exit 1 = remediation required or detection failed.

Update the minimum versions before use. They should come from the
Microsoft advisory or rollout requirement you are responding to.

.NOTES
Author: Eriteach
Version: 1.0
Intune Run Context: System
Run using logged-on credentials: No
#>

$LogRoot = 'C:\MK-LogFiles'
$LogPath = Join-Path -Path $LogRoot -ChildPath 'Detect-DefenderKevVersionCompliance.log'

# Example minimums. Replace with the required Microsoft Defender versions for your rollout.
$MinimumEngineVersion = [version]'1.1.26040.8'
$MinimumPlatformVersion = [version]'4.18.26040.7'

function Write-Log {
param(
[Parameter(Mandatory = $true)]
[string]$Message,

[Parameter(Mandatory = $false)]
[ValidateSet('INFO', 'WARNING', 'ERROR')]
[string]$Level = 'INFO'
)

try {
if (-not (Test-Path -Path $LogRoot)) {
New-Item -Path $LogRoot -ItemType Directory -Force | Out-Null
}

$Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$Entry = '{0} [{1}] {2}' -f $Timestamp, $Level, $Message
$Entry | Out-File -FilePath $LogPath -Append -Encoding UTF8
Write-Host $Entry
}
catch {
Write-Host ('Logging failed: {0}' -f $_.Exception.Message)
}
}

try {
Write-Log -Message 'Starting Defender version compliance detection.'

$Status = Get-MpComputerStatus -ErrorAction Stop
$EngineVersion = [version]$Status.AMEngineVersion
$PlatformVersion = [version]$Status.AMProductVersion

Write-Log -Message ('AMEngineVersion={0}; AMProductVersion={1}; AntivirusSignatureVersion={2}; AntivirusSignatureLastUpdated={3}' -f $Status.AMEngineVersion, $Status.AMProductVersion, $Status.AntivirusSignatureVersion, $Status.AntivirusSignatureLastUpdated)

$EngineCompliant = $EngineVersion -ge $MinimumEngineVersion
$PlatformCompliant = $PlatformVersion -ge $MinimumPlatformVersion

if ($EngineCompliant -and $PlatformCompliant) {
Write-Log -Message 'Device is compliant with the configured Defender minimum versions.'
exit 0
}

if (-not $EngineCompliant) {
Write-Log -Message ('Defender engine is below minimum. Current={0}; Required={1}' -f $EngineVersion, $MinimumEngineVersion) -Level WARNING
}

if (-not $PlatformCompliant) {
Write-Log -Message ('Defender platform is below minimum. Current={0}; Required={1}' -f $PlatformVersion, $MinimumPlatformVersion) -Level WARNING
}

exit 1
}
catch {
Write-Log -Message ('Detection failed: {0}' -f $_.Exception.Message) -Level ERROR
exit 1
}
41 changes: 41 additions & 0 deletions intune/remediations/defender-kev-version-compliance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Defender KEV version compliance remediation

Intune Proactive Remediation pair for checking Microsoft Defender Antivirus engine/platform versions and triggering update mechanisms when an endpoint falls below a configured minimum.

## Files

- `Detect-DefenderKevVersionCompliance.ps1` - exits `1` when engine or platform versions are below configured minimums.
- `Remediate-DefenderKevVersionCompliance.ps1` - runs Defender update mechanisms and logs before/after versions.

## Intended use

Use this when a security advisory, known exploited vulnerability response, or internal baseline requires a specific Microsoft Defender engine/platform minimum.

The script does **not** decide the minimum versions for you. Update these variables before deployment:

```powershell
$MinimumEngineVersion = [version]'1.1.26040.8'
$MinimumPlatformVersion = [version]'4.18.26040.7'
```

## Intune settings

Recommended settings:

- Run this script using the logged-on credentials: **No**
- Enforce script signature check: according to your signing model
- Run script in 64-bit PowerShell: **Yes**
- Assignment: pilot first, then staged rollout

## Safety notes

- Detection is read-only.
- Remediation only triggers Microsoft Defender update mechanisms.
- Both scripts log to `C:\MK-LogFiles`.
- Use a pilot assignment first and validate Intune remediation output before broad rollout.

## Related docs

- Microsoft Intune remediations: https://learn.microsoft.com/en-us/intune/intune-service/fundamentals/remediations
- Get-MpComputerStatus: https://learn.microsoft.com/en-us/powershell/module/defender/get-mpcomputerstatus
- Update-MpSignature: https://learn.microsoft.com/en-us/powershell/module/defender/update-mpsignature
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# ============================================================================
# Eriteach Scripts
# Author: Robel (https://github.com/Thugney)
# Repository: https://github.com/Thugney/eriteach-scripts
# License: MIT
# ============================================================================

<#
.SYNOPSIS
Oppdaterer Microsoft Defender og validerer motor- og plattformversjon.

.DESCRIPTION
Intune Proactive Remediation remediation script for Microsoft Defender
Antivirus version compliance. The script updates Defender security
intelligence, triggers the local Defender command-line update mechanism,
and logs before/after versions for evidence.

Exit 0 = device is compliant after remediation.
Exit 1 = device remains below minimum or remediation failed.

Update the minimum versions before use. They should come from the
Microsoft advisory or rollout requirement you are responding to.

.NOTES
Author: Eriteach
Version: 1.0
Intune Run Context: System
Run using logged-on credentials: No
#>

$LogRoot = 'C:\MK-LogFiles'
$LogPath = Join-Path -Path $LogRoot -ChildPath 'Remediate-DefenderKevVersionCompliance.log'

# Example minimums. Replace with the required Microsoft Defender versions for your rollout.
$MinimumEngineVersion = [version]'1.1.26040.8'
$MinimumPlatformVersion = [version]'4.18.26040.7'

function Write-Log {
param(
[Parameter(Mandatory = $true)]
[string]$Message,

[Parameter(Mandatory = $false)]
[ValidateSet('INFO', 'WARNING', 'ERROR')]
[string]$Level = 'INFO'
)

try {
if (-not (Test-Path -Path $LogRoot)) {
New-Item -Path $LogRoot -ItemType Directory -Force | Out-Null
}

$Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$Entry = '{0} [{1}] {2}' -f $Timestamp, $Level, $Message
$Entry | Out-File -FilePath $LogPath -Append -Encoding UTF8
Write-Host $Entry
}
catch {
Write-Host ('Logging failed: {0}' -f $_.Exception.Message)
}
}

function Get-DefenderVersionState {
$Status = Get-MpComputerStatus -ErrorAction Stop

return [PSCustomObject]@{
EngineVersion = [version]$Status.AMEngineVersion
PlatformVersion = [version]$Status.AMProductVersion
SignatureVersion = $Status.AntivirusSignatureVersion
SignatureLastUpdated = $Status.AntivirusSignatureLastUpdated
}
}

try {
Write-Log -Message 'Starting Defender version compliance remediation.'

$Before = Get-DefenderVersionState
Write-Log -Message ('Before: Engine={0}; Platform={1}; Signature={2}; SignatureLastUpdated={3}' -f $Before.EngineVersion, $Before.PlatformVersion, $Before.SignatureVersion, $Before.SignatureLastUpdated)

try {
Write-Log -Message 'Running Update-MpSignature.'
Update-MpSignature -ErrorAction Stop
}
catch {
Write-Log -Message ('Update-MpSignature failed: {0}' -f $_.Exception.Message) -Level WARNING
}

$MpCmdRun = Join-Path -Path $env:ProgramFiles -ChildPath 'Windows Defender\MpCmdRun.exe'
if (Test-Path -Path $MpCmdRun) {
try {
Write-Log -Message 'Running MpCmdRun signature update.'
Start-Process -FilePath $MpCmdRun -ArgumentList '-SignatureUpdate' -Wait -NoNewWindow -ErrorAction Stop
}
catch {
Write-Log -Message ('MpCmdRun signature update failed: {0}' -f $_.Exception.Message) -Level WARNING
}
}
else {
Write-Log -Message ('MpCmdRun not found at {0}' -f $MpCmdRun) -Level WARNING
}
Comment on lines +88 to +100

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

What are the documented/typical install locations of Microsoft Defender MpCmdRun.exe on current Windows versions, including platform-serviced paths?

💡 Result:

On current Windows versions, the Microsoft Defender command-line utility, MpCmdRun.exe, is documented to reside in two primary locations [1][2]. 1. C:\Program Files\Windows Defender 2. C:\ProgramData\Microsoft\Windows Defender\Platform<antimalware platform version>\ The path C:\ProgramData\Microsoft\Windows Defender\Platform<antimalware platform version> (often referred to as the platform-serviced path) is the recommended location [1][2]. Microsoft advises that the latest version of the utility is always available within this folder if it exists on the system [1][2]. Because these directories are not included in the system PATH environment variable by default, you must navigate to the directory or use the full path to execute the file [1][2]. Microsoft provides an official script snippet to programmatically identify and switch to the most current version of the utility: (set "_done=" & if exist "%ProgramData%\Microsoft\Windows Defender\Platform" (for /f "delims=" %d in ('dir "%ProgramData%\Microsoft\Windows Defender\Platform" /ad /b /o:-n 2^>nul') do if not defined _done (cd /d "%ProgramData%\Microsoft\Windows Defender\Platform%d" & set _done=1)) else (cd /d "%ProgramFiles%\Windows Defender")) >nul 2>&1 [1][2] This approach is the standard practice for ensuring that scripts and automated tasks interact with the most recent, serviced version of the Defender platform [1][2][3].

Citations:


MpCmdRun.exe lookup is incomplete and misses platform-serviced Defender installations.

Line 88 only checks $env:ProgramFiles\Windows Defender\MpCmdRun.exe. Microsoft documents two primary locations for MpCmdRun.exe: the legacy Program Files\Windows Defender directory and the platform-serviced path at $env:ProgramData\Microsoft\Windows Defender\Platform\<version>\MpCmdRun.exe. The platform path is the recommended location and contains the latest serviced version. On many endpoints, this causes the script to skip the signature update and reduces remediation success rates.

Suggested diff
-    $MpCmdRun = Join-Path -Path $env:ProgramFiles -ChildPath 'Windows Defender\MpCmdRun.exe'
-    if (Test-Path -Path $MpCmdRun) {
+    $MpCmdRunCandidates = @(
+        (Join-Path -Path $env:ProgramFiles -ChildPath 'Windows Defender\MpCmdRun.exe'),
+        (Get-ChildItem -Path "$env:ProgramData\Microsoft\Windows Defender\Platform" -Directory -ErrorAction SilentlyContinue |
+            Sort-Object Name -Descending |
+            ForEach-Object { Join-Path -Path $_.FullName -ChildPath 'MpCmdRun.exe' } |
+            Select-Object -First 1)
+    ) | Where-Object { $_ -and (Test-Path -Path $_) }
+
+    $MpCmdRun = $MpCmdRunCandidates | Select-Object -First 1
+    if ($MpCmdRun) {
         try {
             Write-Log -Message 'Running MpCmdRun signature update.'
             Start-Process -FilePath $MpCmdRun -ArgumentList '-SignatureUpdate' -Wait -NoNewWindow -ErrorAction Stop
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@intune/remediations/defender-kev-version-compliance/Remediate-DefenderKevVersionCompliance.ps1`
around lines 88 - 100, The MpCmdRun.exe lookup in the remediation script is
incomplete and only checks the legacy location at $env:ProgramFiles\Windows
Defender\MpCmdRun.exe, missing the platform-serviced installation path. Modify
the code before the Test-Path check on line 88 to search for MpCmdRun.exe in
both locations: first attempt to locate it at $env:ProgramData\Microsoft\Windows
Defender\Platform\<version>\MpCmdRun.exe (the recommended platform-serviced
path), then fall back to the legacy $env:ProgramFiles\Windows
Defender\MpCmdRun.exe location. Ensure the script uses whichever path is found,
allowing it to successfully update signatures on endpoints using the newer
platform-serviced Defender installation.


Start-Sleep -Seconds 20
$After = Get-DefenderVersionState
Write-Log -Message ('After: Engine={0}; Platform={1}; Signature={2}; SignatureLastUpdated={3}' -f $After.EngineVersion, $After.PlatformVersion, $After.SignatureVersion, $After.SignatureLastUpdated)

if ($After.EngineVersion -ge $MinimumEngineVersion -and $After.PlatformVersion -ge $MinimumPlatformVersion) {
Write-Log -Message 'Device is compliant after remediation.'
exit 0
}

Write-Log -Message ('Device remains below minimum. Engine={0}/{1}; Platform={2}/{3}' -f $After.EngineVersion, $MinimumEngineVersion, $After.PlatformVersion, $MinimumPlatformVersion) -Level ERROR
exit 1
}
catch {
Write-Log -Message ('Remediation failed: {0}' -f $_.Exception.Message) -Level ERROR
exit 1
}