如何使用Powershell获取事件消息?
$FilterXML = '<QueryList>
<Query Id="0" Path="System">
<Select Path="System">*[System[Provider[@Name="Service Control Manager"] and (Level=2)]]</Select>
</Query>
</QueryList>'
$Errors = Get-WinEvent -FilterXml $FilterXML
$Errors = $Errors | ?{ $_.ToXml().Contains("SomeService") }
问题是对于每个对象,Message 属性都是 null。我可以使用方法 .ToXml() 获取一些信息,但无法获取您可以在常规选项卡下的 Windows 事件查看器中看到的消息。
如果我使用 Get-EventLog cmdlet,则消息属性返回字符串 关于一些错误。
源“服务控制”中事件 ID“-1073734793”的描述 找不到经理。本地计算机可能没有 必要的注册表信息或消息 DLL 文件来显示 消息,否则您可能没有访问它们的权限。下列 信息是事件的一部分:'SomeService', '2', '0', '3', 'Run 配置的恢复程序'
$FilterXML = '<QueryList>
<Query Id="0" Path="System">
<Select Path="System">*[System[Provider[@Name="Service Control Manager"] and (Level=2)]]</Select>
</Query>
</QueryList>'
$Errors = Get-WinEvent -FilterXml $FilterXML
$Errors = $Errors | ?{ $_.ToXml().Contains("SomeService") }
Problem is that for every object, Message property is null. I can get some info using method .ToXml(), but I can't get message that you could see in windows event viewer under general tab.
If I use Get-EventLog cmdlet, the message property returns string
about some error.
The description for Event ID '-1073734793' in Source 'Service Control
Manager' cannot be found. The local computer may not have the
necessary registry information or mess age DLL files to display the
message, or you may not have permission to access them. The following
information is part of the event:'SomeService', '2', '0', '3', 'Run
the configured recovery program'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情,我相信这相当于你正在尝试的事情。
我想 Get-WinEvent 能够读取那些作为“错误消息”出现的命令:
我尝试了两个等效的命令。使用
Git-WinEvent
获得预期消息,并使用Get-EvenLog
获得“错误”消息:Try something like this, which I believe is equivalent to what you were trying.
I suppose
Get-WinEvent
is able to read those that come as "error message":I tried two equivalent commands. Got the expected message with
Git-WinEvent
and the "error" message that you got withGet-EvenLog
:你能用 WMI 获取消息吗?
Can you get the message with WMI?