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?

イベントログをcsvで出力したい

Last updated at Posted at 2025-04-13

初めに

イベントログで何かしらを調査したい時にイベントビューアーを使うけど
イベントビューアーって重いしログ提出に向かないわ...そう思ったそこの奥さん
PowerShellでcsvに出力できるんですよ。

コマンド

ってことでコマンドはこちら
C:¥直下にcsvファイルが作成されます

アプリケーションのイベントログを出力する場合
Get-EventLog Application -After "2025/4/12 09:30" -Before "2025/4/12 12:30" | select EventID,EntryType,Message,Source,TimeWritten | Export-Csv -Encoding UTF8 -NoTypeInformation -Path C:\Application.csv
システムのイベントログを出力する場合
Get-EventLog System -After "2025/4/12 09:30" -Before "2025/4/12 12:30" | select EventID,EntryType,Message,Source,TimeWritten | Export-Csv -Encoding UTF8 -NoTypeInformation -Path C:\System.csv
セキュリティのイベントログを出力する場合(時間かかるかも)
Get-EventLog Security -After "2025/4/12 09:30" -Before "2025/4/12 12:30" | select EventID,EntryType,Message,Source,TimeWritten | Export-Csv -Encoding UTF8 -NoTypeInformation -Path C:\Security.csv

(一応)引数の解説

一応引数とかオプションの解説
Get-EventLog hogehoge

  • Application:ユーザーやソフトウェアが出力するログ。アプリの作り込みが雑だと、エラー発生してるのにイベントが記録されていないことがよくある
  • System:Windows OSやドライバが出力するログ。割とちゃんと記録されているけれども、メーカーによってはログが雑なことがたまにある(N〇〇西とかヌ〇〇ボとか)
  • Security:ログオンや監査ポリシーなどセキュリティ関連のログ。基本的にWindowsが出しているため細かさと正確性は高い。が、ログサイズが多すぎるのと、たまにすり抜けというか欲しいログが検知されていないことがある。

-After "2025/4/12 09:30" ⇒ 2025/4/12 09:30 より後のログを取得します
-Before "2025/4/12 12:30" ⇒ 2025/4/12 12:30 より前のログを取得します
select EventID,EntryType,Message,Source,TimeWritten ⇒ イベントID、エラーレベル、ログ内容、ログのソース(何のアプリか的な)、ログ日時 を取得します
Export-Csv ⇒ csvに出力します
-Encoding UTF8 ⇒ 文字コードを指定します。csvが文字化けする場合はDefaultを指定してみてね
-NoTypeInformation ⇒ csv1行目の型宣言的なものを出力しないよ宣言
-Path C:\Security.csv ⇒ csvファイル出力先

最後に

最近ようやく気付いたんですよ
なんかごちゃごちゃやるよりも、とりあえずワンライナーでデータだけ出して、
あとは使い慣れたExcelとかで加工させた方が運用がスムーズに回るってことを...

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?