Get-EventLog 中缺少事件描述,但存在于 Get-WinEvent 和事件查看器中

ben*_*kah 5 powershell windows-event-log

当我使用 Get-EventLog 在 powershell 中查询它们时,缺少事件日志事件的许多事件描述,但是当我使用 Get-WinEvent 在 powershell 中查询它们或在常规事件查看器 eventvwr.msc 中查看它们时,它们会出现

这是 Get-EventLog 的输出:

PS U:\> Get-EventLog -LogName System -Source Microsoft-Windows-Kernel-Power

   Index Time          EntryType   Source                 InstanceID Message
   ----- ----          ---------   ------                 ---------- -------
   11985 Apr 02 13:42  Information Microsoft-Windows...          172 The description for Event ID '172' in Source 'Microsoft-Windo...
   11968 Apr 02 13:41  Information Microsoft-Windows...          109 The description for Event ID '109' in Source 'Microsoft-Windo...
   11732 Apr 02 09:41  Information Microsoft-Windows...          172 The description for Event ID '172' in Source 'Microsoft-Windo...
   11714 Apr 02 09:40  Information Microsoft-Windows...          109 The description for Event ID '109' in Source 'Microsoft-Windo...
   10363 Mar 29 14:28  Information Microsoft-Windows...          172 The description for Event ID '172' in Source 'Microsoft-Windo...
   10346 Mar 29 14:28  Information Microsoft-Windows...          109 The description for Event ID '109' in Source 'Microsoft-Windo...
Run Code Online (Sandbox Code Playgroud)

这是一个完整的事件:

PS U:\> Get-EventLog -LogName System -Source Microsoft-Windows-Kernel-Power | select -first 1 | fl


Index              : 11985
EntryType          : Information
InstanceId         : 172
Message            : The description for Event ID '172' in Source 'Microsoft-Windows-Kernel-Power' 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:'2', '6'
Category           : (203)
CategoryNumber     : 203
ReplacementStrings : {2, 6}
Source             : Microsoft-Windows-Kernel-Power
TimeGenerated      : 2019-04-02 13:42:01
TimeWritten        : 2019-04-02 13:42:01
UserName           : NT AUTHORITY\SYSTEM
Run Code Online (Sandbox Code Playgroud)

这是 Get-WinEvent 的输出:

PS C:\WINDOWS\system32> Get-WinEvent -LogName System -FilterXPath "<QueryList>
>>   <Query Id='0' Path='System'>
>>     <Select Path='System'>*[System[Provider[@Name='Microsoft-Windows-Kernel-Power']]]</Select>
>>   </Query>
>> </QueryList>"


   ProviderName: Microsoft-Windows-Kernel-Power

TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
2019-04-02 13:42:01            172 Information      Connectivity state in standby: Disconnected, Reason: NIC compliance
2019-04-02 13:41:44            109 Information      The kernel power manager has initiated a shutdown transition....
2019-04-02 09:41:08            172 Information      Connectivity state in standby: Disconnected, Reason: NIC compliance
2019-04-02 09:40:51            109 Information      The kernel power manager has initiated a shutdown transition....
2019-03-29 14:28:26            172 Information      Connectivity state in standby: Disconnected, Reason: NIC compliance
2019-03-29 14:28:09            109 Information      The kernel power manager has initiated a shutdown transition....
Run Code Online (Sandbox Code Playgroud)

Get-WinEvent 能够毫无问题地呈现消息“备用连接状态:断开连接,原因:NIC 合规性”。

这是事件查看器中的第一个事件,消息也正确显示:

在事件查看器中查看的带有完整消息的第一个返回事件

该消息表明注册表或事件消息 dll 文件可能有问题,但我已经检查过,它们不是:

PS U:\> Get-ItemPropertyValue HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\System\Microsoft-Windows-Kernel-Power -name EventMessageFile
C:\WINDOWS\system32\microsoft-windows-kernel-power-events.dll
PS U:\> test-path C:\WINDOWS\system32\microsoft-windows-kernel-power-events.dll
True
PS U:\> $handle = [System.IO.File]::OpenRead("C:\WINDOWS\system32\microsoft-windows-kernel-power-events.dll")
PS U:\> $handle.CanRead
True
Run Code Online (Sandbox Code Playgroud)

这表明

  1. 源在注册表中配置
  2. 文件存在
  3. 我可以读取文件

这与 Microsoft-Windows-Kernel-Power 源无关。许多其他事件源也会发生同样的情况。但并非所有事件源。例如 Get-EventLog 正确呈现 Microsoft-Windows-Winlogon 源消息:

PS U:\> Get-EventLog -LogName System -Source Microsoft-Windows-Winlogon | select -first 1 | ft

   Index Time          EntryType   Source                 InstanceID Message
   ----- ----          ---------   ------                 ---------- -------
   12100 Apr 02 13:58  Information Microsoft-Windows...         7001 User Logon Notification for Customer Experience Improvement P...
Run Code Online (Sandbox Code Playgroud)

我已经多次重新启动我的机器,我运行了系统文件检查器,它没有报告任何问题。

版本详情:

PS U:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.316
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.316
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Run Code Online (Sandbox Code Playgroud)

Luc*_*uke 3

我相信您遇到了 Get-EventLog cmdlet 的限制,该 cmdlet 已被 Get-WinEvent cmdlet 取代。根据官方文档:

包含 EventLog 名词的 PowerShell cmdlet 仅适用于 Windows 经典事件日志,例如应用程序、系统或安全性。若要获取在 Windows Vista 和更高版本的 Windows 中使用 Windows 事件日志技术的日志,请使用 Get-WinEvent。

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-eventlog?view=powershell-5.1

尽管您正在查询系统事件日志,从技术上讲,它应该不受此影响,因为它是经典事件日志,但这些类型的事件日志条目(以 开头Microsoft-Windows-)仅开始出现在 Vista 及更高版本中,所以我很确定这一点是“设计使然”。

老实说,我不确定为什么你不直接使用Get-WinEventcmdlet,因为它确实有效。