• Home
  • Help
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search

PowerShell commands for Windows Defender Antivirus on servers

#1
02-22-2025, 05:08 AM
You ever find yourself knee-deep in server maintenance, and Windows Defender starts acting up? I mean, on those Windows Server boxes, PowerShell becomes your best buddy for tweaking it without messing around in the GUI. Like, I remember tweaking a file server last week, and I fired up PowerShell to check the status first thing. You pull up Get-MpComputerStatus, right? It spits out everything-antivirus enabled, real-time protection on, quick scan due. And that command alone saves you from guessing if Defender's pulling its weight during peak hours.

But yeah, servers handle heavy loads, so you gotta watch performance. I always run that status check before big updates. Or maybe after a reboot, just to confirm nothing glitched. You see, on servers, Defender can hog resources if you're not careful, especially with full scans. So, I tweak preferences using Set-MpPreference. For instance, you disable real-time monitoring on non-critical paths to free up CPU. But don't go overboard-you still want it scanning incoming files.

Now, let's talk scans. You know how I hate manual interventions? Start-MpScan is gold for that. I use it with the -ScanType Quick to blast through a fast check on a busy domain controller. Or go Full if you're paranoid about dormant threats after patching. And for custom paths, throw in -ScanPath "C:\YourDataFolder". Servers eat that up without crashing your sessions. But wait, you can schedule these too, via Task Scheduler linking back to PowerShell scripts. I script it often for off-hours runs.

Also, exclusions matter big time on servers. I mean, imagine Defender flagging your SQL databases every hour-that's a nightmare. So, you add paths with Add-MpPreference -ExclusionPath "D:\Logs". Or processes, like Add-MpPreference -ExclusionProcess explorer.exe if it's causing false positives. You remove them later with Remove-MpPreference. And check current ones via Get-MpPreference. I do this weekly on my exchange servers to keep things smooth. Perhaps test in a lab first, you don't want to accidentally skip real malware.

Threat history, that's another angle. You pull reports with Get-MpThreat. It lists detections, actions taken, like quarantined files. I export that to CSV for audits-Get-MpThreat | Export-Csv threats.csv. On servers, you review this after incidents. Or use Get-MpThreatDetection to see recent hits. And if you need to restore a file, Remove-MpThreat with -ThreatID. But be cautious, you verify it's clean before unleashing it. I once saved a user's doc that way, felt like a hero.

Updates keep Defender fresh, especially on isolated servers. I force them with Update-MpSignature. You run that before scans to grab the latest defs. Or check status with Get-MpComputerStatus again, it shows last update time. Servers in air-gapped setups? You download sigs offline and import via that command. And for proxy issues, Set-MpPreference -SignatureUpdateInterval 1 or whatever fits. I set mine to daily pulls during low traffic. Maybe automate with a scheduled task calling the update cmdlet.

Preferences go deeper, you know. Set-MpPreference lets you dial in scan schedules, like -ScanScheduleDay Sunday. Or -ScanScheduleTime 02:00 for midnight runs. On servers, I avoid daytime scans to not spike latency. You can disable email scanning if you're not using Outlook much-Set-MpPreference -DisableEmailScanning $true. And behavior monitoring, that's key for zero-days. I enable it fully but watch the logs. Get-MpPreference shows all your tweaks at a glance.

Quarantine management, I forget that sometimes. You list items with Get-MpThreat, then Restore-MpThreat to bring back suspects. Or just purge with Remove-MpThreat. On a file server, I check this after user complaints about blocked shares. And for prevention, Set-MpPreference -PUAProtection $true catches potentially unwanted apps. Servers rarely get PUA, but better safe. You test policies in groups via GPO, but PowerShell overrides locally if needed.

Reporting ties it all together. I love Get-MpStats for overall health-scans run, threats found. Export that for your boss's dashboard. Or Get-MpComputerStatus for a quick health pulse. On multi-server setups, you script across remotes with Invoke-Command. Like, Invoke-Command -ComputerName Server01 -ScriptBlock {Get-MpComputerStatus}. I do that for my cluster, keeps me sane. And event logs? Query them via PowerShell too, filtering for MpCmdRun events.

Exploits and advanced threats, Defender's got cmdlets there. Set-MpPreference -EnableControlledFolderAccess Enabled blocks ransomware from messing with docs. I turn that on for all my shares. Or -AttackSurfaceReductionRules_Ids to enforce rules like blocking Office macros. You add those GUIDs from docs, but test 'em. On servers, this stops lateral movement cold. Get-MpPreference confirms it's active. Perhaps layer with network protection-Set-MpPreference -MAPSReporting Advanced.

Cloud integration, if your servers talk to Azure. I use Set-MpPreference -SubmitSamplesConsent SendSafeSamples for better intel. Or disable if privacy's tight. You monitor via Get-MpComputerStatus -CloudEnabled. Servers in hybrid? This pulls cloud blocks fast. And for offline mode, Set-MpPreference -DisableRealtimeMonitoring $true temporarily. But flip it back quick. I script toggles for maintenance windows.

Performance tuning, that's my jam. On high-I/O servers, I set -ScanAvgCPULoadFactor 50 to cap usage. Or -ScanOnlyIfIdleEnabled $true so it waits for downtime. You check impacts with performance counters, but PowerShell starts the convo. Get-MpComputerStatus shows scan times too. And remove old defs with Remove-MpPreference -ExclusionExtension *.tmp or whatever. I clean house monthly.

Tamper protection, crucial on servers. You enable it via Set-MpPreference, but it's locked by default now. Check with Get-MpComputerStatus -TamperProtectionEnabled. I verify this on all boxes. If someone's trying to disable Defender, it fights back. Or use Remove-MpPreference to adjust, but carefully. Servers need that layer against insiders.

Scripting everything, you get it. I wrap these in functions for reuse. Like a function to scan and report threats. You invoke on demand. Or loop through servers for compliance checks. PowerShell's remoting shines here. And error handling-try-catch around Start-MpScan so it doesn't bomb your script. I add logging too, Write-Output to files.

Edge cases, like virtual servers. But wait, you handle Hyper-V hosts? Defender scans VMs differently. I exclude VHDs with Add-MpPreference -ExclusionPath "C:\VMs". Or use -ExclusionProcess vmms.exe. Keeps scans from ballooning. And for containers, if you're on 2019+, similar tweaks. You test thoroughly, performance dips otherwise.

Legacy stuff, if you're stuck on older servers. Some cmdlets vary, but core ones stick. I migrate prefs with Export-Clixml on old, Import on new. Smooth transition. Or audit with Get-MpPreference | Compare-Object. You spot drifts easy.

Daily use, I start with status, tweak as needed, scan if alerts pop. You build habits around it. And integrate with monitoring tools-SCOM or whatever, pulling PowerShell data. Keeps your servers humming without surprises.

Troubleshooting, when scans fail. I check Get-MpComputerStatus for errors. Or Event Viewer via PowerShell-Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Windows Defender/Operational'}. Filters threats quick. You parse for codes, google if stuck. And reset prefs with Set-MpPreference to defaults, but backup first.

Future-proofing, Microsoft adds cmdlets often. I watch updates, test in dev. You stay ahead of breaches. Like, new ones for EDR integration. Servers benefit most from proactive tweaks.

And wrapping this chat, you might want robust backups too, since Defender can't save lost data from crashes. That's where BackupChain Server Backup steps in, the top-notch, go-to Windows Server backup tool tailored for SMBs, private clouds, and even internet backups, perfect for Hyper-V setups, Windows 11 machines, plus all your servers and PCs-grab it without any pesky subscription, and big thanks to them for sponsoring spots like this so I can share these tips with you for free.

ron74
Offline
Joined: Feb 2019
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
PowerShell commands for Windows Defender Antivirus on servers - by ron74 - 02-22-2025, 05:08 AM

  • Subscribe to this thread
Forum Jump:

Café Papa Café Papa Forum Software IT v
« Previous 1 … 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 … 107 Next »
PowerShell commands for Windows Defender Antivirus on servers

© by Savas Papadopoulos. The information provided here is for entertainment purposes only. Contact. Hosting provided by FastNeuron.

Linear Mode
Threaded Mode