PowerShell Genie

Check Windows Defender status

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-MpComputerStatus returns the live state of the Defender engine as a single object.

The script

1PS> Get-MpComputerStatus | Select-Object AMServiceEnabled,AntivirusEnabled,RealTimeProtectionEnabled,AntivirusSignatureVersion

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 AMServiceEnabled AntivirusEnabled RealTimeProtectionEnabled AntivirusSignatureVersion
    2 ---------------- ---------------- ------------------------- -------------------------
    3 True True True 1.417.512.0
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-MpComputerStatus | Select-Object AMServiceEnabled,AntivirusEnabled,RealTimeProtectionEnabled,AntivirusSignatureVersion
    1. Stage 1Get-MpComputerStatusPositional values or no named parameters
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-MpComputerStatus returns the live state of the Defender engine as a single object. Select-Object pulls the four fields that answer the question directly: whether the antimalware service is up, whether antivirus protection is enabled, whether real-time scanning is active, and which signature version is currently loaded.

      Adapting it

      Substitute AntivirusSignatureLastUpdated or QuickScanEndTime into the property list when the concern is scan freshness rather than configuration state.

      Requirements

      The Windows Defender feature must be present; some Server Core installs omit it.

      If the result is unexpected

      Get-MpComputerStatus errors with a message about the operation being unavailable, or it returns flags suggesting healthy protection on a machine where a third-party product is doing the scanning.

      The Defender cmdlets ship with the Defender feature, so a Server Core installation without that feature has no cmdlet to call. Where a third-party antivirus registers with the Security Center, Defender drops into passive mode and its own flags keep reporting on its state rather than on whether anything is protecting the machine.

      1. Confirm the module is present with Get-Module -ListAvailable Defender.
      2. Check Get-Service WinDefend, since a disabled service accounts for the operation error.
      3. Read AMRunningMode, which distinguishes normal mode from passive and EDR block mode.
      4. Query the registered antivirus products through the SecurityCenter2 namespace to see what is actually in charge.
      5. Install the feature with Install-WindowsFeature Windows-Defender if this host is meant to be using it.

      Validate the result

      AMRunningMode reports Normal on hosts where Defender is the intended product, and the SecurityCenter2 query lists it as the registered provider.

      Keep the check reliable

      Check AMRunningMode instead of the enabled flags in any compliance report, because those flags stay true in passive mode.

      Primary documentation

      Windows services and processes documentation

      Continue
      Genie guideCheck Windows Defender status

      Get-MpComputerStatus returns the live state of the Defender engine as a single object.