Search Tools Links Login

On-Demand File Scanning with Microsoft Defender via PowerShell


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:

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:

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!

About this post

Posted: 2023-07-30
By: dwirch
Viewed: 151 times

Categories

Tutorials

Security

Scripting

Powershell

Windows

PowerShell Code Cache

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.