Powershell - Get-WinEvent

问题描述 投票:1回答:2

我一直在寻找这个“Level”意味着运行Get-WinEvent的地方。

例如,

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

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

powershell powershell-v2.0 get-winevent
2个回答
5
投票

让我们试着找出:

#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

获取事件的级别。级别表示事件的严重性。对于级别的名称,获取LevelDisplayName属性的值

#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

0
投票

有关详细信息,请参阅此链接。 MSDN

实际上,您正在寻找一个winmeta.xml文件,但它会为基本值提供以下内容:

  • LogAlways:0,
  • 关键:1,
  • 错误:2,
  • 警告:3,
  • 信息:4,
  • 详细:5,
  • 16岁以下的休息是保留的
© www.soinside.com 2019 - 2024. All rights reserved.