0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Get-WinEventの結果を整形したい

0
Last updated at Posted at 2025-09-28

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?