当我使用 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...
以下是完整活动:
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
以下是 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....
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
这表明
- 源在注册表中配置
- 文件存在
- 我可以读取文件
这并非仅限于 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...
我已经多次重启了我的计算机,并且运行了系统文件检查器,它没有报告任何问题。
版本详细信息:
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
答案1
我认为您在使用 Get-EventLog cmdlet 时遇到了限制,该 cmdlet 已被 Get-WinEvent cmdlet 取代。根据官方文档:
包含 EventLog 名词的 PowerShell cmdlet 仅适用于 Windows 经典事件日志,例如应用程序、系统或安全。要获取在 Windows Vista 及更高版本的 Windows 中使用 Windows 事件日志技术的日志,请使用 Get-WinEvent。
虽然您正在查询系统事件日志,但从技术上讲它不应受此影响,因为它是一个经典的事件日志,但这些类型的事件日志条目(以 开头Microsoft-Windows-
)只在 Vista 及更高版本中才开始出现,所以我很确定这是“设计使然”。
老实说,我不确定为什么你不直接使用 cmdlet Get-WinEvent
,因为它确实有效。