Powershell 获取事件日志-缺少DLL

Powershell 获取事件日志-缺少DLL,powershell,event-log,Powershell,Event Log,我正在尝试为我们的帮助台代理创建一个基本脚本,该脚本允许他们查看特定的日志文件,而无需打开事件查看器以节省他们在电话中的时间 但是,我在PowerShell中遇到了一个问题,某些事件ID没有显示实际的事件日志消息 如果我运行以下命令: Get-EventLog -ComputerName $env:COMPUTERNAME ` -LogName System ` -InstanceId 12 ` -Source Mic

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

但是,我在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'
我看到另一个关于使用
Get WinEvent
的例子,不幸的是,在我工作的环境中这是不可能的。

阅读并遵循:

获取WinEvent 模块:
Microsoft.PowerShell.Diagnostics

从本地和服务器上的事件日志和事件跟踪日志文件获取事件 远程计算机

注释

  • 此cmdlet旨在取代运行Windows Vista和更高版本Windows的计算机上的
    Get EventLog
    cmdlet。
    Get EventLog
    仅在经典事件日志中获取事件。
    获取事件日志
    保留在Windows PowerShell中以实现向后兼容性
Get-WinEvent
cmdlet允许您通过使用XPath查询、结构化XML查询和简化哈希表查询(以下示例中使用后者)过滤事件:

另请参见(过时)
获取事件日志的相关输出:


您是否同时查看来自同一台计算机的事件?我假设您希望从消息中提取系统启动时间。在这种情况下,该数据仍在您返回的“错误”中。这是消息中的最后一个字符串:
'2018-03-18T16:59:34.495252300Z'
。不太理想,但您可以像解析“真实”消息一样解析此字符串。“这在我工作的环境中不可能”是什么意思?为什么不可能?@EBGreen是的,是同一台电脑。谢谢。由于某种原因,昨天在测试时,我在本地主机上尝试时遇到了一个RPC错误,我相信这正是我正在使用的环境。通过对上面代码的一些调整,今天就可以使用了。
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...
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-...