Search code examples
powershellwindows-10antiviruswindows-defenderpowershell-6.0

Why does scanning a single file in Powershell with Start-MpScan take longer than using the context menu option?


I'm currently writing a script to use Windows Defender for scanning various files. I've read the documentation on Microsoft Docs - StartMpScan, however I am running into an issue when attempting to scan a single file or folder.

Documentation dictates that I use -ScanPath to indicate a selective scan, so it would look like this;

Start-MpScan -ScanPath "C:\Path\To\File\or\Folder"

However, when I run the scan it can take upwards of 5-10 minutes to scan a single 1kb file, or folder with a few 1kb files inside! This the case even when using a quickscan. I figured something was wrong with this so I tried using the right-click context option on one of these files to "Scan with Windows Defender..." and each time it was almost instantaneously scanned.

These are my current specs:

OS: Windows 10 Educational

OS Version: 1903

OS Build: 18362.476

Powershell Version: 6.2.3

Am I missing something in my syntax or am I just not that bright?


Solution

  • From my reading of the (pretty poor) documentation, -QuickScan doesn't just scan that path, it does a scan of StartUp and other System items too.

    I think the option you need is -CustomScan - seems to work a lot faster on my PC.