PowerShell: Scripting Windows Defender Scans
Why Script It
Clicking "Scan now" in the Windows Security app gives you a scan and no record of it. A scripted scan gives you a result you can log, schedule, or run across several machines — and it lets you target a specific path rather than scanning everything.
Defender exposes this through the Mp* cmdlets. They are built in on Windows 10 and 11; no module to install.

Check The Current State
Get-MpComputerStatus
The fields worth reading:
AntivirusEnabled— is real-time protection onRealTimeProtectionEnabled— the specific setting, which can be off while the service runsAntivirusSignatureVersion/AntivirusSignatureLastUpdated— an old signature date is the most common reason a scanned machine is still infectedQuickScanAge/FullScanAge— days since the last scan, or4294967295for never
That last value is a useful audit: on a fleet, "never scanned" is a much more actionable finding than "0 detections".
Update, Then Scan
Update-MpSignature
Start-MpScan -ScanType QuickScan
-ScanType accepts QuickScan or FullScan. A quick scan checks memory, startup items and the usual infection locations; it takes minutes. A full scan reads every file and takes hours on a large drive, which is why it belongs at 3am rather than in a script someone waits on.
To scan one path — the useful case after downloading something:
Start-MpScan -ScanType CustomScan -ScanPath 'D:\Downloads'
CustomScan requires -ScanPath and will not accept C:\ as a whole-volume target; use FullScan for that.
Reading The Results
The scan itself returns nothing useful. Detections are separate:
# what the engine has found, historically
Get-MpThreatDetection
# the threat catalogue entries
Get-MpThreat
Get-MpThreatDetection is the one you want in a script — each entry has the threat name, the file path, the action taken and the time. Filter to recent:
Get-MpThreatDetection |
Where-Object { $_.InitialDetectionTime -gt (Get-Date).AddDays(-1) } |
Select-Object ThreatID, InitialDetectionTime, Resources
A custom MpPreference target is a common alternative: define a named scan with its own exclusions and run it by name.
Scheduling It
$action = New-ScheduledTaskAction -Execute 'PowerShell.exe' `
-Argument '-NoProfile -Command "Update-MpSignature; Start-MpScan -ScanType FullScan"'
$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At 3am
$set = New-ScheduledTaskSettingsSet -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Hours 6)
Register-ScheduledTask -TaskName 'DefenderFullScan' -Action $action -Trigger $trigger `
-Settings $set -User 'SYSTEM' -RunLevel Highest
Six hours of execution limit is deliberate — a full scan on a large drive can genuinely take that long, and the default 3 days is not a useful safety net.
Why Your Script Might Do Nothing
Tamper Protection. When enabled, Defender blocks changes made through PowerShell and the registry — exclusions, disabling real-time protection, changing scan settings. Set-MpPreference -DisableRealtimeMonitoring $true will appear to succeed and have no effect.
That is the feature working as designed: it exists to stop malware doing exactly what you are trying to do. If you legitimately need to change these settings, do it in the Security app or turn Tamper Protection off temporarily as an administrator.
Third-party antivirus. If another product is registered, Defender goes into passive mode and Start-MpScan does nothing useful. Get-MpComputerStatus shows AMServiceEnabled and the engine state.
Running unelevated. Most Mp* write cmdlets need an administrator session. Reads work unelevated; Update-MpSignature and scans may not.


Is Defender Good Enough?
My honest position: yes, for a home machine and most small businesses.
Independent testing has put Defender's detection rates close to the paid products for several years, and it has two advantages the others do not — it is already installed, and it does not add a second full-time scanner competing for disk access. The measurable cost of third-party suites on an older machine is real.
Where it falls short: some advanced and fileless techniques, and management depth if you are running a large fleet. If you have a compliance requirement that names a product, that is a different conversation.
What matters far more than which engine you run: it is up to date and it actually scanned. Those two facts are what this article's script checks, and they are the ones people get wrong.
Don't trust the download button. Trust the hash.
If this was useful, More hands-on tech guides at TechGeek. No pressure — read it whenever it's useful.