Powershell - 获取 WinEvent

标签 powershell powershell-2.0 get-winevent

我一直在到处寻找,只是想弄清楚这个“级别”意味着运行 Get-WinEvent。

例如,

Get-WinEvent –FilterHashtable @{logname=’application’; level=2; starttime=$time; id=20}

level=2 在这里代表什么? 我问的原因是我正在尝试验证每个日志的严重性,并且 level=2 是否代表与严重性相关的任何内容。

最佳答案

让我们试着找出答案:

#Get sample object
$t = Get-WinEvent -MaxEvents 1 -FilterHashtable @{ Logname='application'; level=2 }

#Explore properties and type
$t.GetType().Fullname
System.Diagnostics.Eventing.Reader.EventLogRecord

快速 msdn 搜索 EventLogRecord将我们指向 EventLogRecord.Level Property

Gets the level of the event. The level signifies the severity of the event. For the name of the level, get the value of the LevelDisplayName property

#Check out Level vs LevelDisplayName
$t | Format-Table -Property Level, LevelDisplayName -AutoSize

Level LevelDisplayName
----- ----------------
    2 Error 

在我的日志中快速搜索以列出一些级别值:

Get-WinEvent @{ logname='application' } | Select-Object Level, LevelDisplayName -Unique | Sort-Object Level

Level LevelDisplayName
----- ----------------
    0 Information     
    2 Error           
    3 Warning         
    4 Information     

它还在 Level-property 页面上说它使用 StandardEventLevel 枚举,所以让我们列出它的值:

[enum]::GetValues([System.Diagnostics.Eventing.Reader.StandardEventLevel]) | Select-Object {$_}, {$_.value__ }

           $_ $_.value__ 
           -- -----------
    LogAlways           0
     Critical           1
        Error           2
      Warning           3
Informational           4
      Verbose           5

关于Powershell - 获取 WinEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35442767/

相关文章:

powershell - Invoke-Command:找不到可以接受参数的位置参数

c# - 在 PowerShell v2 中编译新类型 - Cookie Aware WebClient

xml - 如何使用Powershell从xml过滤以获取启动持续时间?

azure - Powershell 函数 -WhatIf 用于没有 -WhatIf 支持的 cmdlet?

linux - 有没有办法在 Windows 中获取有关进程的详细信息?

powershell - 功能等同的串联多个不同长度列表中的项目

string - PowerShell 中的多行字符串到单行字符串的转换

powershell - 从路径创建文件夹目录?