首页 > 解决方案 > 在 PowerShell 中解析 Windows Defender 事件日志

问题描述

我需要解析 Windows Defender 事件日志。用这个命令

Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | Where-Object { $_.LevelDisplayName -ne "Information" } | Select-Object -ExpandProperty Message

我得到这个输出:

Windows Defender Antivirus has detected malware or other potentially unwanted software.
 For more information please see the following:
https://go.microsoft.com/fwlink/?linkid=37020&name=Trojan:Win32/TFTPD32&threatid=12892&enterprise=0
        Name: Trojan:Win32/TFTPD32
        ID: 12892
        Severity: Severe
        Category: Trojan
        Path: file:_\\server\share\path\file1.exe::$DATA; file:_\\server\share\path\file2.exe::$DATA; file:_\\server\share\path\file3.exe::$DATA;
        Detection Origin: Network share
        Detection Type: Concrete
        Detection Source: Real-Time Protection
        User: DOMAIN\user
        Process Name: C:\Windows\SMSProxy\Microsoft.StorageMigration.Proxy.Service.exe
        Signature Version: AV: 1.335.1263.0, AS: 1.335.1263.0, NIS: 1.335.1263.0
        Engine Version: AM: 1.1.18000.5, NIS: 1.1.18000.5

当有多个文件并且以 Path: 开头的行很长时,它会被截断。不是消息属性,而只是行。当我使用事件日志查看器查看记录时,该行已完成。有没有办法获得全长的线路?

我只需要从 Message 属性(多行字符串)中获取带有 Name: 和 Path: 的行。如何使用例如 RegEx 获得它^\s+(Name|Path):

更新:
我不匹配事件日志记录,即使在事件日志中路径行被截断。
问题的第二部分仍然存在:如何从多行属性中只获取一些行?

标签: powershellevent-logwindows-defender

解决方案


推荐阅读