Get-WinEvent の出力結果をごにょごにょする
とりあえず関数を用意。
# 除外条件を適用するフィルタ
Filter Remove-WinEvent {
Param(
$ProviderName,
$Id,
$Message
)
if ($ProviderName -ne $_.ProviderName) { return $_ }
if ($Id -ne $_.Id) { return $_ }
if ($Message) {
if ($_.Message -notmatch $Message) { return $_ }
}
}
イベントログ毎の条件
# イベントログの検索条件
$ApplicationLogHash = @{
LogName = "Application"
StartTime = (Get-Date).AddHours(-12) # 過去12時間
Level = 1,2,3 # 重大とエラーと警告
}
# 列の定義
$columns = & {
@{ N="TimeCreated"; E={ $_.TimeCreated } }
@{ N="Source"; E={ $_.ProviderName + "(" + $_.id + ")" } }
@{ N="Level"; E={ $_.LevelDisplayName } }
@{ N="Message"; E={ $_.Message } }
}
イベントログの検索実行
# 検索結果が 0 件の場合にエラーとなるため ErrorAction で抑制
$params = @{
ErrorAction = "SilentlyContinue"
FilterHashTable = $ApplicationLogHash
Oldest = $True
}
Get-WinEvent @params `
| Remove-WinEvent ".NET Runtime" 1022 `
| Select-Object $columns