2

第一个命令在事件日志中创建一个条目,它似乎正在工作,因为我可以在事件查看器中看到消息数据。问题是当从 powershell 读取它时,消息字段为空。

write-eventlog System -source 'Microsoft-Windows-Kernel-General' -eventid 999 -message 'Kernel something or other'

get-winevent -filterHashTable @{Logname = 'System'; ID = '999'}| select-object -first 10

也许这张照片能更好地解释它。请注意消息列是空白的。 在此处输入图像描述

4

2 回答 2

2

事件被正确写入,要读回它,请使用:

get-winevent -filterHashTable @{Logname = 'System'; ID = '999'}| 
    select-object -first 10 | select timecreated,providername,
    @{n="Message";e={$_.properties.Value}}

启动时在消息栏中看不到它的原因很明显eventvwr

找不到来自源 Microsoft-Windows-Kernel-General 的事件 ID 999 的描述。引发此事件的组件未安装在本地计算机上,或者安装已损坏。您可以在本地计算机上安装或修复组件。

如果您想从自定义来源编写自定义消息,请使用New-EventLogcmdlet,这里是脚本专家的教程:http: //blogs.technet.com/b/heyscriptingguy/archive/2013/06/20/how-to-use-powershell- to-write-to-event-logs.aspx

于 2014-09-26T08:39:29.490 回答
1

这是最终使它起作用的片段。感谢 Raf 提供我找到此答案的链接。

$source = "Some Name"
If ([System.Diagnostics.EventLog]::SourceExists("$source") -eq $false)
{New-EventLog -LogName $log -Source "$source"}
于 2014-10-05T13:45:10.143 回答