How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (2024)

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (1)

Jump To:

  • Check state
  • Download updates
  • Quick scan
  • Full scan
  • Custom scan
  • Offline scan
  • Active scan
  • Change settings

On Windows 11, the Microsoft Defender Antivirus is the default anti-malware system that offers real-time protection against viruses, ransomware, and other types of threats, including those from hackers.

The antivirus comes configured with the optimal settings to protect your files and installation, and you can even manage various aspects of the application through the Windows Security app. However, you can also manage the Microsoft Defender Antivirus with commands through PowerShell (in addition to Command Prompt).

Using commands, you can review settings, download updates, perform different kinds of scans, change settings, enable features not available through the user interface, and much more.

This how-to guide will walk you through the essential commands to control the Windows 11 antivirus with PowerShell.

How to check state of the Defender Antivirus

To confirm whether the Microsoft Defender Antivirus is running on your computer, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to check the Microsoft Defender Antivirus status and pressEnter:Get-MpComputerStatus
  4. Confirm theAntivirusEnabledoption is set toTrue, which indicates that the antivirus is running.

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (2)

Once you complete the steps, the PowerShell command will output the antivirus status, including other information, such as product and engine version, update details, and more.

How to check for updates on Defender Antivirus

To check, download, and install definition updates for the Defender Antivirus on Windows 11, use these steps:

Get the Windows Central Newsletter

All the latest news, reviews, and guides for Windows and Xbox diehards.

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to check to update the Defender Antivirus on Windows 11 and pressEnter:Update-MpSignature

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (3)

After you complete the steps, the PowerShell command will download and install any available updates. (This command may take a few moments to run.)

How to run quick malware scan on Defender Antivirus

To run a quick virus scan on Windows 11, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to run a quick malware scan and pressEnter:Start-MpScan -ScanType QuickScan

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (4)

Once you complete the steps, the antivirus will run a quick scan on your computer.

How to run full malware scan on Defender Antivirus

To run a full malware scan with the Microsoft Defender Antivirus, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to run a full malware scan on Windows 11 and pressEnter:Start-MpScan -ScanType FullScan

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (5)

Quick tip: If you want to terminate an ongoing scan, you can run this "C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -Cancel command from Command Prompt (admin).

After you complete the steps, the antivirus will perform a full scan on Windows 11.

How to run custom malware scan on Defender Antivirus

To run a custom malware scan with the Defender Antivirus, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to run a custom Defender Antivirus scan and pressEnter:Start-MpScan -ScanType CustomScan -ScanPath PATH\TO\SCAN\LOCATION

In the command, change the path with the folder location to scan. For instance, this command scans the "Downloads" folder:Start-MpScan -ScanType CustomScan -ScanPath "C:\Users\USER\Downloads"

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (6)

Once you complete the steps, the Windows 11 anti-malware will scan the locations you specified in the command.

How to run offline malware scan on Defender Antivirus

An offline scan is a feature that allows you to scan, detect, and remove viruses that can't be deleted when the system is running. This scan will restart the computer. As a result, it's recommended to save your files and close your applications before proceeding.

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to run an offline Defender Antivirus scan and pressEnter:Start-MpWDOScan

After you complete the steps, the system will restart automatically in the Windows Recovery Environment (WinRE), and the Microsoft Defender Antivirus will scan the system to detect and remove any threat affecting your installation.

After the scan, the system will restart automatically again, and you will be able to view the scan report onWindows Security>Virus & thread protection>Protection history.

How to remove active malware scan on Defender Antivirus

To delete active threats on Windows 11, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to remove active threats using Defender Antivirus and pressEnter:Remove-MpThreat

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (7)

Once you complete the steps, the default antivirus of Windows 11 will scan and remove any active threats from the device. (This option only works for threats the Microsoft Defender Antivirus hasn't already mitigated.)

How to change settings on Defender Antivirus

On Windows 11, you can also use PowerShell to change various settings of the antivirus, such as exclusions and quarantine retention, and you can schedule scans and change other preferences.

View settings

To view every setting available on the Windows 11 antivirus, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to view the current configuration of Defender Antivirus and pressEnter:Get-MpPreference

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (8)

After you complete the steps, the PowerShell command will generate a list with all the preferences that you are able to configure on the Microsoft Defender Antivirus.

Exclude folder

The Defender Antivirus ships with an option that allows you to exclude a drive or folder location from the real-time protection and scan schedules.

To exclude a scan location on Microsoft Defender Antivirus, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to exclude a folder from the antivirus and pressEnter:Set-MpPreference -ExclusionPath PATH\LOCATION

In the command, replace"PATH\LOCATION"with the path to exclude. For example, this command excludes the "Videos" folder from being scanned:Set-MpPreference -ExclusionPath C:\Users\USER\Videos.

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (9)

Once you complete the steps, the antivirus will continue to protect your computer and files, but it will exclude the locations you specified with PowerShell.

You can always remove the exclusion using theRemove-MpPreference -ExclusionPath "PATH\TO\FOLDER"command. In the command, remember to set the exclude path you want to remove.

Exclude file type

The Defender Antivirus also includes an option to exclude specific file types.

To prevent the Windows 11 antivirus from scanning a specific file type, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to exclude a file type from the antivirus and pressEnter:Set-MpPreference -ExclusionExtension EXTENSION

In the command, replace"EXTENSION"with the extension you want to exclude. For instance, this command excludes the Microsoft Excel files from being scanned:Set-MpPreference -ExclusionExtension xlsx.

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (10)

After you complete the steps, the anti-malware will continue to protect the system and files, but it'll ignore the file types you specified with the PowerShell command.

You can always remove the exclusion using theRemove-MpPreference -ExclusionExtension EXTENSIONcommand. In the command, remember to set the exclude extension you want to remove.

Quarantine deletion schedule

To specify how many days the antivirus should retain a quarantined item before deleting it, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to schedule the number of days to keep items in quarantine and pressEnter:Set-MpPreference -QuarantinePurgeItemsAfterDelay DAYS

In the command, replace "DAYS" with the number of days to keep items. For instance, this command will set the antivirus to retain the items for 60 days before deletion:Set-MpPreference -QuarantinePurgeItemsAfterDelay 60

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (11)

  • Quick tip:To keep the items indefinitely, you can use the value of "0" (zero) or no value.

Once you complete the steps, the Microsoft Defender Antivirus will delete the items in quarantine after the number of days specified in the command.

Schedule quick virus scan

To schedule a quick virus scan on Windows 11 from PowerShell, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to schedule a daily quick scan and pressEnter:Set-MpPreference -ScanScheduleQuickScanTime SCHEDULE

In the command, replace"SCHEDULE"with the time in 24-hour format to run the scan. For instance, this command prepares a quick scan every day at 3:00 am, local time:Set-MpPreference -ScanScheduleQuickScanTime 03:00:00

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (12)

After completing the steps, the Windows 11 antivirus will run a quick scan on the date and time specified in the command.

Schedule full virus scan

To schedule a full virus scan from PowerShell, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to schedule a full scan and pressEnter:Set-MpPreference -ScanParameters 2
  4. Type the following command to schedule a day and pressEnter:Set-MpPreference -RemediationScheduleDay DAY

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (13)

In the command, change the"DAY"for the day (number) you want to run the malware scan. Available options include 0 (everyday), 1 through 7 (Monday through Sunday), and 8 (never). For instance, this command schedules the full scan for Saturdays:Set-MpPreference -RemediationScheduleDay 7

  • Quick tip:You can re-apply the default scanning schedule with the option"8."
  1. Type the following command to specify a time for the scan and pressEnter:Set-MpPreference -RemediationScheduleTime TIME

In the command, change"TIME"with the time in the 24-hour format to run the scan. For instance, this command schedules a full scan at 3:00 am, local time:Set-MpPreference -RemediationScheduleTime 03:00:00.

Once you complete the steps, the antivirus will run a complete system scan to detect and delete malware at the date and time you specified in the command.

Disable virus protection

The Microsoft Defender Antivirus allows you to turn off real-time protection using a specific command in case you have to perform an action conflicting with the anti-malware. The only caveat is that you can only use this option after disabling"Tamper Protection"fromWindows Security>Virus & threat protection>Virus & threat protection (Manage settings).

To disable the real-time protection on the Microsoft Defender Antivirus, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to temporarily turn off the Defender Antivirus on Windows 11 and pressEnter:Set-MpPreference -DisableRealtimeMonitoring $true

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (14)

After you complete the steps, the Windows 11 antivirus will stop protecting your computer until the next reboot.

If you can't restart the system, you can re-enable the feature using theSet-MpPreference -DisableRealtimeMonitoring $falsecommand.

External storage scan

The Microsoft Defender Antivirus does not monitor for threats on removable drives, but it's something possible to do through the command options.

To enable the scanning of external drives, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to allow external drive scanning on Windows 11 and pressEnter:Set-MpPreference -DisableRemovableDriveScanning $false

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (15)

Once you complete the steps, the Defender Antivirus will scan removable drives during a full malware scan on Windows 11.

Disable archive scan

In addition to scanning folders and files, the Microsoft Defender Antivirus can also scan and remove viruses from archival containers (such as Zip, Cab, and others). However, if you have a good reason, it's possible to disable this feature.

To turn off virus scanning inside archival containers, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to disable archival container scanning and pressEnter:Set-MpPreference -DisableArchiveScanning $true

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (16)

After you complete the steps, the antivirus will skip scanning Zip, Cab, and other types of archival containers.

You can always revert the behavior with theSet-MpPreference -DisableArchiveScanning $falsecommand.

Enable network storage scan

To allow the Defender Antivirus to scan network drives, use these steps:

  1. OpenStart.
  2. Search forPowerShell, right-click the top result, and select theRun as administratoroption.
  3. Type the following command to enable the Defender Antivirus to scan network drives and pressEnter:Set-MpPreference -DisableScanningMappedNetworkDrivesForFullScan $false

How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (17)

Once you complete the steps, when running a full malware scan, the antivirus will also scan mapped network drives.

You can always revert the behavior with theSet-MpPreference -DisableScanningMappedNetworkDrivesForFullScan $truecommand.

These are the most interesting preferences that you can configure in the Microsoft Defender Antivirus, but you can configure a slew of other options.

More resources

For more helpful articles, coverage, and answers to common questions about Windows 10 and Windows 11, visit the following resources:

  • Windows 10 on Windows Central — All you need to know
  • Windows 11 on Windows Central — All you need to know
How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (18)

Mauro Huculak

Mauro Huculak has been a Windows How-To Expert contributor for WindowsCentral.com for nearly a decade and has over 15 years of experience writing comprehensive guides. He also has an IT background and has achieved different professional certifications from Microsoft, Cisco, VMware, and CompTIA. He has been recognized as a Microsoft MVP for many years.

No comments yetComment from the forums

    How to control Microsoft Defender Antivirus from PowerShell on Windows 11 (2024)
    Top Articles
    Authorization Request and Authorization Code | Kount
    15 quick tips for reducing food waste and becoming a Food hero
    Fort Morgan Hometown Takeover Map
    Tryst Utah
    El Paso Pet Craigslist
    Mopaga Game
    Die Windows GDI+ (Teil 1)
    360 Training Alcohol Final Exam Answers
    Klustron 9
    Pickswise the Free Sports Handicapping Service 2023
    Chase Claypool Pfr
    Jesus Revolution Showtimes Near Chisholm Trail 8
    Tripadvisor Near Me
    Jasmine Put A Ring On It Age
    Gfs Rivergate
    Wisconsin Women's Volleyball Team Leaked Pictures
    FAQ: Pressure-Treated Wood
    Echo & the Bunnymen - Lips Like Sugar Lyrics
    Huntersville Town Billboards
    Curry Ford Accident Today
    Georgia Cash 3 Midday-Lottery Results & Winning Numbers
    Uncovering The Mystery Behind Crazyjamjam Fanfix Leaked
    A Cup of Cozy – Podcast
    Truvy Back Office Login
    Studentvue Calexico
    Leben in Japan – das muss man wissen - Lernen Sie Sprachen online bei italki
    Tactical Masters Price Guide
    Core Relief Texas
    Little Einsteins Transcript
    FSA Award Package
    What does wym mean?
    Where Can I Cash A Huntington National Bank Check
    Serenity Of Lathrop - Manteca Photos
    KITCHENAID Tilt-Head Stand Mixer Set 4.8L (Blue) + Balmuda The Pot (White) 5KSM175PSEIC | 31.33% Off | Central Online
    Avance Primary Care Morrisville
    Telegram update adds quote formatting and new linking options
    Babylon 2022 Showtimes Near Cinemark Downey And Xd
    How to play Yahoo Fantasy Football | Yahoo Help - SLN24152
    Cookie Clicker The Advanced Method
    craigslist: modesto jobs, apartments, for sale, services, community, and events
    Sofia Franklyn Leaks
    فیلم گارد ساحلی زیرنویس فارسی بدون سانسور تاینی موویز
    Mother Cabrini, the First American Saint of the Catholic Church
    bot .com Project by super soph
    Paradise leaked: An analysis of offshore data leaks
    1990 cold case: Who killed Cheryl Henry and Andy Atkinson on Lovers Lane in west Houston?
    San Diego Padres Box Scores
    Uno Grade Scale
    Verilife Williamsport Reviews
    The Missile Is Eepy Origin
    How To Find Reliable Health Information Online
    Latest Posts
    Article information

    Author: Kieth Sipes

    Last Updated:

    Views: 6588

    Rating: 4.7 / 5 (47 voted)

    Reviews: 86% of readers found this page helpful

    Author information

    Name: Kieth Sipes

    Birthday: 2001-04-14

    Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

    Phone: +9663362133320

    Job: District Sales Analyst

    Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

    Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.