How to Manage Windows Security with PowerShell

In this guide you will discover the most important commands and methods for managing Windows security from PowerShell.

In this guide, I’ll explain several tricks for managing Windows security with PowerShell . If you’re not entirely familiar with this tool, I invite you to check out our dedicated guide. It shows you what PowerShell is and its most basic commands. Once you’ve reviewed the basic concepts, you’ll be ready to manage your PC from the command line.

By the way, don’t forget that the comments section is open . At the end of the article, you’ll be able to leave your opinion, mention anything I should add, or even point out any errors. Your contributions will undoubtedly make this article even better.

Table of Contents

Managing Windows security with PowerShell, step by step

PowerShell has some commands that will help you check the status of your computer’s security systems. Others also make it easier to take certain actions , such as performing a quick scan of your computer. Learn how to manage Windows security with PowerShell below.

Keep this in mind!

To run all these commands you need to run PowerShell as administrator .

Microsoft Defender Status

The first step to checking if everything is working is to check the current status of Microsoft Defender . To do this, you can use this command:

Get-MpComputerStatus

This command will show you a very comprehensive report from your Windows antivirus. It includes relevant information such as:

  • If the antivirus is enabled.
  • If there is real-time protection.
  • When was the last update?
  • If any threats have been detected recently.

Keep this command handy for when you think it’s convenient to confirm that everything is working correctly without opening the graphical interface.

Check for updates for Defender

Microsoft frequently updates virus definitions for Defender. These updates are crucial for the system to recognize the latest threats. Did you know you can force the update? Here’s the command:

Update-MpSignature

This command checks for new definitions and installs them, all from the console. It’s a very quick way to ensure you have the latest version of the antivirus engine and its threat database.

Quick PC Scan

Okay, now imagine you suspect something’s wrong. The best thing you can do is a quick scan. To do that, run this command:

Start-MpScan -ScanType QuickScan

The quick scan examines the most vulnerable aspects of your system and ensures there are no problems. Among other things, Microsoft Defender will look at running processes, temporary files, the startup registry, and more. In just a few minutes, you’ll have a first idea if there’s anything unusual on your computer.

Deep PC Scan

When you want to be absolutely sure or already suspect a threat is active , it’s best to run a full scan. The command is this:

Start-MpScan -ScanType FullScan

This type of scan is more in-depth. It scans all files, hard drives, and connected drives. Be careful! It can take a while, especially if you have a lot of storage, but it’s the most effective against malware hiding in unusual corners.

Scan for viruses in specific directories

PowerShell also allows you to directly target a folder or file that you suspect. Here’s an example of this command:

Start-MpScan -ScanPath «C:\Users\[username]\Downloads»

With this tool, you can focus the scan on the area where you downloaded a suspicious file. Of course, you can use it not only with the downloads folder, but with any other folder. It’s very practical if you don’t want to waste time scanning the entire system and only need to check a specific spot.

Offline Scanning

Sometimes viruses hide so well that they’re difficult to remove while Windows is running. That’s where offline scanning comes in:

Start-MpWDOScan

This command restarts the computer and launches a scan before Windows fully loads. It’s like intervening in the system before it’s fully awake, which is ideal for removing the most resistant malware.

Remove all active threats

If Defender has detected threats, you can ask it to remove them directly from PowerShell. Use the following command:

Remove-MpThreat

This command deletes all identified threats. It’s especially useful if you don’t want to wait for Defender to act on its own or if you’re already sure you want to remove any detected malware.

How to manage security in Windows with PowerShell by changing Defender settings

Finally, I’ll tell you about some commands that will allow you to modify Microsoft Defender settings from PowerShell. You’ll be able to do things like change the quarantine duration or schedule specific scans. I’ve prepared a table with the main commands:

Command Function Explanation
Get-MpPreference See all settings This command allows you to see a list of all configurable parameters.
Set-MpPreference -ScanScheduleQuickScanTime 12:00 Schedule quick scan Defines an automatic quick scan at 12:00 (in 24h format).
Set-MpPreference -ScanScheduleDay 1 Weekly scan Set Monday as the scan day. You can change the number depending on the day of the week.
Set-MpPreference -QuarantinePurgeItemsAfterDelay 14 Change quarantine time Defines that quarantined files are deleted after 14 days.
Set-MpPreference -DisableRealtimeMonitoring $true Disable real-time protection For testing or controlled environments only. Never use on a PC in everyday use.
Add-MpPreference -ExclusionPath «C:\Games» Exclude folder from analysis Defender won’t scan that path. Ideal for folders with false positives.

Have you started managing Windows security with PowerShell? Leave your thoughts below. We’ll be in touch!

Leave a Comment

Scroll to Top