Configure and manage Microsoft Defender Antivirus using the MpCmdRun.exe command-line tool

The command below is a straightforward way to run a custom scan using Windows Defender (Microsoft Defender Antivirus) from the command line. Let’s break down each part of the command to understand its functionality:

"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 3 -File "{Path_To_Directory}"

Breakdown of the Command

  1. %ProgramFiles%\Windows Defender\MpCmdRun.exe:
    • This specifies the path to the MpCmdRun.exe executable, which is the command-line utility for Microsoft Defender Antivirus.
    • %ProgramFiles% is an environment variable that points to the Program Files directory (usually C:\Program Files).
  2. -Scan:
    • This parameter tells MpCmdRun.exe that you want to perform a scan.
  3. -ScanType 3:
    • This specifies the type of scan to perform. The value 3 corresponds to a custom scan. Here are the possible values for -ScanType:
      • 1: Quick scan
      • 2: Full scan
      • 3: Custom scan
  4. -File “{Path_To_Directory}”:
    • This specifies the path to the directory or file you want to scan. In this example, “{Path_To_Directory}” is a placeholder for the path you want to scan.

Example Usage

To scan a specific directory, replace “{Path_To_Directory}” with the actual path. For example, if you want to scan the 

C:\Users\Username\Documents directory, the command would be:

"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 3 -File "C:\Users\Username\Documents"


This command leverages Windows Defender’s command-line tool to perform a custom scan on the specified directory. Its value lies in its ability to script and automate antivirus scans for specific locations on your system, making your management tasks more efficient.