【问题标题】:Filter duplicate messages in PowerShell?在 PowerShell 中过滤重复消息?
【发布时间】: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


    【解决方案1】:

    您正在寻找Group-Object cmdlet。示例:

    $Result | Group-Object EventId
    

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 2020-03-31
      • 2014-07-22
      • 1970-01-01
      • 2010-12-28
      • 2022-01-24
      • 1970-01-01
      • 2017-08-21
      • 2022-06-17
      相关资源
      最近更新 更多