本文介绍了如何使用 PowerShell 管理 Windows 自带的杀毒软件,操作包括查看威胁、隔离区恢复、管理排除项等。
Microsoft Defender防病毒扫描完成后,无论是按需扫描还是计划扫描,结果都将被记录,可以查看扫描结果。
一、PowerShell查看扫描结果
使用 PowerShell cmdlet 查看扫描结果
以下 cmdlet 将返回终结点上的每个检测。 如果存在对同一威胁的多个检测,则会根据每次检测的时间单独列出每个检测:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Get-MpThreatDetection
ActionSuccess : True AdditionalActionsBitMask : 0 AMProductVersion : 4.18.23050.9 CleaningActionID : 2 CurrentThreatExecutionStatusID : 1 DetectionID : {16219B17-0B4C-4F57-9240-E99F1966D48D} DetectionSourceTypeID : 3 DomainUser : test\test InitialDetectionTime : 2023/8/1 14:17:46 LastThreatStatusChangeTime : 2023/8/1 14:18:13 ProcessName : C:\Windows\explorer.exe RemediationTime : 2023/8/1 14:18:13 Resources : {file:_C:\xxx.exe} ThreatID : 265744 ThreatStatusErrorCode : 0 ThreatStatusID : 3 PSComputerName :
|
- 可以指定 -ThreatID 以将输出限制为仅显示特定威胁的检测。
- 恢复隔离区的文件也需要指定 -ThreatID
二、还原隔离的文件
列出所有威胁
1 2 3 4 5 6 7 8 9 10 11 12 13
| Get-MpThreat
CategoryID : 23 DidThreatExecute : False IsActive : False Resources : RollupStatus : 1 SchemaVersion : 1.0.0.0 SeverityID : 4 ThreatID : 265744 ThreatName : Program:Win32/Wacapew.C!ml TypeID : 0 PSComputerName :
|
恢复隔离区文件到原始位置
1 2 3 4 5 6
| & 'C:\Program Files\Windows Defender\MpCmdRun.exe' -Restore -Name Trojan:Win32/Wacatac.H!ml -All
Restoring the following quarantined items:
ThreatName = Trojan:Win32/Wacatac.H!ml file:C:\xxx\xxx.exe quarantined at 2023/8/1 6:08:22 (UTC) was restored
|
三、管理防火墙排除项
查看排除项列表
使用 PowerShell 检索排除列表
1 2 3 4 5 6
| $WDAVprefs = Get-MpPreference $WDAVprefs.ExclusionExtension $WDAVprefs.ExclusionPath
C:\BaiduNetdiskDownload C:\Users\test\Downloads
|
添加排除项
使用 PowerShell 添加排除项
1
| Add-MpPreference -ExclusionPath c:\排除目录
|
删除排除项
使用 PowerShell 移除排除项
1
| Remove-MpPreference -ExclusionPath c:\排除目录
|
四、使用 PowerShell 运行扫描
使用专用命令行工具 mpcmdrun.exe 执行防病毒扫描
1 2 3 4
| & 'C:\ProgramData\Microsoft\Windows Defender\Platform\4.18.23050.9-0\MpCmdRun.exe' -scan -scantype 1
Scan starting... Scan finished.
|
ScanType 的值为:
- 0 默认,根据配置
- 1 快速扫描
- 2 完全扫描
- 3 文件和目录自定义扫描。
扫描工具参数参考
脱机扫描