【问题标题】:Get-EventLog - Missing DLL获取事件日志 - 缺少 DLL
【发布时间】:2018-04-26 03:20:49
【问题描述】:

我正在尝试为我们的帮助台代理创建一个基本脚本,这将允许他们查看特定的日志文件,而无需打开事件查看器以节省他们在电话上的时间。

但是,我在使用 PowerShell 时遇到问题,其中某些事件 ID 没有显示实际的事件日志消息。

如果我运行以下命令:

Get-EventLog -ComputerName $env:COMPUTERNAME `
             -LogName System `
             -InstanceId 12 `
             -Source Microsoft-Windows-Kernel-General | 
    Select-Object -Property Message

我希望收到实际事件日志中显示的消息:

相反,我得到了一些类似的东西:

The description for Event ID '12' in Source
'Microsoft-Windows-Kernel-General' 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.  The following information is part of the event:'10',
'0', '15063', '726', '0', '0',                    
'2018-03-18T16:59:34.495252300Z'

我看到另一个 thread 关于使用 Get-WinEvent 不幸的是,这在我工作的环境中是不可能的。

【问题讨论】:

  • 您是否两次都在同一台计算机上查看事件?
  • 我假设您想从消息中提取系统启动时间。在这种情况下,该数据仍处于您返回的“错误”中。它是消息中的最后一个字符串:'2018-03-18T16:59:34.495252300Z'。不理想,但您可以像解析“真实”消息一样解析此字符串。
  • “这在我工作的环境中是不可能的”是什么意思?为什么不可能?
  • @EBGreen 是同一台计算机。

标签: powershell event-log


【解决方案1】:

阅读并关注documentation:

获取-WinEvent

模块:Microsoft.PowerShell.Diagnostics

从本地和本地的事件日志和事件跟踪日志文件中获取事件 远程计算机。
…
备注

  • 此 cmdlet 旨在替换运行 Windows Vista 和更高版本 Windows 的计算机上的 Get-EventLog cmdlet。 Get-EventLog 仅在经典事件日志中获取事件。 Get-EventLog 保留在 Windows PowerShell 中以实现向后兼容性。

Get-WinEvent cmdlet 允许您使用 XPath 查询、结构化 XML 查询和简化的哈希表查询(后者用于以下示例)来过滤事件:

PS D:\PShell> Get-WinEvent -ComputerName $env:COMPUTERNAME `
        -FilterHashtable @{
            ProviderName = 'Microsoft-Windows-Kernel-General';
            Id           = '12';
            LogName      = 'System' } `
        -MaxEvents 3 | 
    Format-Table -Property  RecordId, Message


RecordId Message                                                               
-------- -------                                                               
   14103 The operating system started at system time ‎2018‎-‎04‎-‎25T06:13:0...
   13957 The operating system started at system time ‎2018‎-‎04‎-‎24T05:34:3...
   13826 The operating system started at system time ‎2018‎-‎04‎-‎22T07:49:0...

另请参阅(过时的)Get-EventLog:

的相关输出
PS D:\PShell> Get-EventLog -ComputerName $env:COMPUTERNAME `
        -LogName System `
        -InstanceId 12 `
        -Source Microsoft-Windows-Kernel-General `
        -Newest 3 | 
    Select-Object -Property Index, Message


Index Message                                                                  
----- -------                                                                  
14103 The description for Event ID '12' in Source 'Microsoft-Windows-Kernel-...
13957 The description for Event ID '12' in Source 'Microsoft-Windows-Kernel-...
13826 The description for Event ID '12' in Source 'Microsoft-Windows-Kernel-...

【讨论】:

  • 谢谢。出于某种原因,在昨天测试这个时,我在尝试本地主机时遇到了一个 RPC 错误,我相信这只是我工作的环境。今天通过对上面的代码进行一些调整就可以工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
相关资源
最近更新 更多