【问题标题】:Filter EventLog based on date根据日期过滤 EventLog
【发布时间】:2018-05-17 19:39:05
【问题描述】:

我正在尝试根据今天的日期通过 PowerShell 从事件日志中提取一些信息。

到目前为止,我的代码如下:

$today = (Get-Date).ToString("dd/MM/yyyy")
Get-EventLog Security | where {$_.EventID -eq 4624} | where {$_.TimeGenerated -eq $today}

现在我打印了今天的结果,可以确认输出的日期是 04/12/2017,我还打印了 EventID 对象中 TimeGenerated 属性的日期,并且还显示了相同的日期格式。

关于我哪里出错了有什么想法吗?

【问题讨论】:

    标签: powershell get-eventlog


    【解决方案1】:

    TimeGenerated 属性包含 DateTime 值,而不是字符串,因此不要将其与日期字符串进行比较。此外,您应该尽可能通过Get-EventLog 参数进行过滤,因为该过滤发生在源头。这在查询远程事件日志以减少通过网络传输的数据量时尤其重要。

    $today    = (Get-Date).Date
    $tomorrow = $today.AddDays(1)
    
    Get-EventLog -LogName Security -InstanceId 4626 -After $today -Before $tomorrow
    

    【讨论】:

      猜你喜欢
      • 2021-02-05
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 2021-04-02
      • 2020-02-15
      相关资源
      最近更新 更多