On-Demand File Scanning with Microsoft Defender via PowerShell

By | 2023-07-30

Welcome to this comprehensive guide where we will delve into the specifics of how to run an on-demand Antivirus (AV) scanning on a file using Microsoft Defender and PowerShell.

The default antivirus software on Windows 10 is Microsoft Defender, previously known as Windows Defender. It provides real-time protection against software threats across email, apps, the cloud, and the web. While it constantly works in the background, ensuring your system’s protection, there might be instances where you need to manually initiate an AV scan on a specific file. This can be achieved effectively using PowerShell, a task-based command-line shell and scripting language built on .NET.

So, let’s get started!

Prerequisites

Before we jump into the procedure, ensure that:

  • You have administrative privileges on your computer.
  • Microsoft Defender is enabled and up-to-date.
  • Running an AV Scan using PowerShell

Step 1: Open PowerShell with Admin Rights

Press Win + X and choose Windows PowerShell (Admin) or Command Prompt (Admin) depending on your system configuration. If you’re using Windows 11, search for PowerShell in the Start menu, right-click the Windows PowerShell app, and choose Run as administrator.

Step 2: Perform the Scan

In order to run an on-demand AV scan, Microsoft Defender offers a PowerShell cmdlet Start-MpScan. This cmdlet initiates a scan on the specified paths. The general syntax of the command is:

Start-MpScan -ScanPath "<PathToTheFile>" -ScanType "<TypeOfTheScan>"

<PathToTheFile> – This is where you provide the full path to the file you wish to scan. Ensure that you replace <PathToTheFile> with the actual path to your file. For instance, if your file is located at C:\Users\YourUsername\Downloads\testfile.txt, this will be the path you provide.

<TypeOfTheScan> – This argument specifies the type of scan to run. The options include:

  • QuickScan – Scans areas that malware is most likely to infect.
  • FullScan – Scans the entire system.
  • CustomScan – Scans the files and folders at the specified scan path.

So, if you want to run a custom scan on a file located at C:\Users\YourUsername\Downloads\testfile.txt, you would run:

Start-MpScan -ScanPath "C:\Users\YourUsername\Downloads\testfile.txt" -ScanType "CustomScan"

This command will start a scan and the result will be shown in the PowerShell window.

Conclusion

PowerShell provides an efficient and swift method for running on-demand scans with Microsoft Defender. It’s always good to have these commands handy, as manual scans can be particularly useful when dealing with suspicious files or in-depth system checks.

However, remember that while manual scans can help, the first line of defense is always having up-to-date antivirus software running in the background, practicing safe browsing habits, and being careful with the files you download and open.

Stay safe, stay protected!

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.