【问题标题】:Pulling EventLogs using powershell from a certain time period从某个时间段使用 powershell 拉事件日志
【发布时间】:2022-06-17 14:40:41
【问题描述】:

我正在尝试运行一个 powershell 脚本,该脚本将在 2 个特定时间之间提取应用程序事件日志。我有以下代码:

$Begin = Get-Date -Date '2/04/2022 14:36:00'
$End = Get-Date -Date '2/04/2022 14:40:00'
Get-EventLog –LogName Application -After $Begin -Before $End

我不断收到以下错误。

Get-Date : Cannot bind parameter because parameter 'Date' is specified more 
than once. To provide multiple values to parameters that can accept multiple 
values, use the array syntax. For example, "-parameter value1,value2,value3".

有谁知道我做错了什么?

【问题讨论】:

  • 我无法使用您帖子中的任何Get-Date 语句重现此错误。您是否尝试过像$begin,$end = Get-Date -Date '2/04/2022 14:36:00' -Date '2/04/2022 14:40:00' 或类似的方式将它们组合起来?请确保您发布的代码实际上是您正在运行的代码:)

标签: powershell


【解决方案1】:

Get-Eventlog itself is depreciated.

您可以像 js2010 建议的那样使用 Get-Winevent。 -filterhashtable 是(我相信)指定时间段的唯一方法。

    $EventLogFilter = @{
        Logname = 'System'
        StartTime = [datetime]::Today.AddHours(-$Hours)
        EndTime = [datetime]::Today
    }

这将为您提供在您指定的最后 $hours 数内发生的所有事情。

This is a list of key-value pairs.

【讨论】:

    【解决方案2】:

    get-winevent 的 filterhashtable 示例。任何可以转换为日期时间的字符串都可以使用。搜索每个日志需要一个 foreach-object 循环。

    get-winevent -filterhashtable @{logname = 'application'; starttime = '12:45 pm'; 
      endtime = '12:50 pm' }
    
    
       ProviderName: gupdate
    
    TimeCreated                      Id LevelDisplayName Message
    -----------                      -- ---------------- -------
    2/7/2022 12:45:19 PM              0
    
    

    【讨论】:

      【解决方案3】:

      $Begin = Get-Date -Date '1/17/2019 08:00:00' $End = Get-Date -Date '1/17/2019 17:00:00' Get-EventLog -LogName System -EntryType Error -After $Begin -Before $End

      Index Time EntryType Source InstanceID Message


      13821 Jan 17 13:40 错误 DCOM 10016 事件 ID 的描述... 13820 Jan 17 13:11 错误 DCOM 10016 事件 ID 的描述... 12372 Jan 17 10:08 错误 DCOM 10016 事件 ID 的描述... 12371 Jan 17 09:04 错误 DCOM 10016 事件 ID 的描述...

      【讨论】:

        猜你喜欢
        • 2014-10-02
        • 2014-07-15
        • 2018-08-13
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多