@echo off setlocal EnableExtensions where powershell.exe >nul 2>nul if errorlevel 1 ( echo PowerShell not found. exit /b 2 ) echo Windows Defender quick status powershell.exe -NoProfile -Command "try { $s = Get-MpComputerStatus -ErrorAction Stop; [pscustomobject]@{ Antivirus = $s.AntivirusEnabled; RealTime = $s.RealTimeProtectionEnabled; SignatureAgeDays = $s.AntivirusSignatureAge; AMService = $s.AMServiceEnabled } | Format-List; if (-not $s.AntivirusEnabled -or -not $s.RealTimeProtectionEnabled) { exit 1 } } catch { Write-Host ('ERROR: ' + $_.Exception.Message); exit 2 }" set "code=%errorlevel%" if not "%code%"=="0" ( echo Defender check finished with code %code%. ) exit /b %code%