【发布时间】:2019-12-18 15:42:45
【问题描述】:
我目前正在学习 PowerShell,并且我制作了一个返回事件日志错误的脚本,是否可以过滤掉多次发生的具有相同“EventID”的事件日志错误,并将其替换为例如“x2” ?
代码:
[dateTime]$oneWeekAgo = (get-date).addDays(-7)
$Result = Get-EventLog -LogName Application -After $oneWeekAgo -Entrytype Error |
Select-Object -Property MachineName, Source, EventID, EntryType, Message, TimeGenerated -Unique |
Out-File ".\new\EventViewer.txt"
我自己的 PC 的示例输出:
MachineName : PC
Source : Office 2016 Licensing Service
EventID : 0
EntryType : 1
Message : The description for Event ID '0' in Source 'Office 2016 Licensing Service' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have
permission to access them.
TimeGenerated : 2019-12-11 06:44:30
MachineName : PC
Source : Microsoft-Windows-Perflib
EventID : 1020
EntryType : 1
Message :
TimeGenerated : 2019-12-11 06:39:05
MachineName : PC
Source : Office 2016 Licensing Service
EventID : 0
EntryType : 1
Message : The description for Event ID '0' in Source 'Office 2016 Licensing Service' cannot be found. The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have
permission to access them.
TimeGenerated : 2019-12-06 22:50:48```
【问题讨论】:
标签: powershell