1. Log名を指定してイベントログを取得する
これが基本の形となります。Log名の指定は必須です。
実行例: System Log を指定した場合
PS> Get-EventLog -LogName "System"
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
69415 3 03 08:29 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
69414 3 03 08:29 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
69413 3 03 08:28 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
69412 3 03 08:28 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
<以下略>
※指定できるLog名は下記のとおりです。Get-Eventlog -List コマンドで確認できます。
No. | Log名 |
---|---|
1 | System |
2 | Application |
3 | Security |
4 | Active Directory Web Services |
5 | DFS Replication |
6 | Directory Service |
7 | DNS Server |
8 | HardwareEvents |
9 | Internet Explorer |
10 | Key Management Service |
11 | Windows PowerShell |
2. 出力結果をList 表示に変更する
デフォルトだと Format-Table という表示形式となっており画面に入り切らない情報が表示されません。表示形式を Format-List という表示形式に変更することで、内容をすべて表示させることができます。
実行例
PS> Get-EventLog -LogName System | Format-List
Index : 70128
EntryType : Information
InstanceId : 1073748860
Message : Software Protection サービスは 実行中 状態に移行しました。
Category : (0)
CategoryNumber : 0
ReplacementStrings : {Software Protection, 実行中}
Source : Service Control Manager
TimeGenerated : 2024/03/03 14:21:12
TimeWritten : 2024/03/03 14:21:12
UserName :
Index : 70127
EntryType : Information
InstanceId : 1073748860
Message : Software Protection サービスは 実行中 状態に移行しました。
Category : (0)
CategoryNumber : 0
ReplacementStrings : {Software Protection, 実行中}
Source : Service Control Manager
TimeGenerated : 2024/03/03 14:20:42
TimeWritten : 2024/03/03 14:20:42
UserName :
<以下略>
3. 表示項目を選択する
※すべての項目を表示させる場合は * を指定します。
実行例: イベントID、発生日、メッセージを表示
PS> Get-EventLog -LogName Security | Select-object EventID, TimeGenerated, Message
EventID TimeGenerated Message
------- ------------- -------
4634 2024/03/03 14:29:33 アカウントがログオフしました。...
4627 2024/03/03 14:29:33 グループ メンバーシップ情報。...
4624 2024/03/03 14:29:33 アカウントが正常にログオンしました。...
4672 2024/03/03 14:29:33 新しいログオンに特権が割り当てられました。...
4634 2024/03/03 14:28:33 アカウントがログオフしました。...
4627 2024/03/03 14:28:33 グループ メンバーシップ情報。...
4624 2024/03/03 14:28:33 アカウントが正常にログオンしました。...
4672 2024/03/03 14:28:33 新しいログオンに特権が割り当てられました。...
4634 2024/03/03 14:28:26 アカウントがログオフしました。...
4627 2024/03/03 14:28:26 グループ メンバーシップ情報。...
<以下略>
実行例: すべての項目を表示
PS> Get-EventLog -LogName System | Select-object *
EventID : 7036
MachineName : WIN201902.test_domain3.test
Data : {115, 0, 112, 0...}
Index : 70152
Category : (0)
CategoryNumber : 0
EntryType : Information
Message : Software Protection サービスは 実行中 状態に移行しました。
Source : Service Control Manager
ReplacementStrings : {Software Protection, 実行中}
InstanceId : 1073748860
TimeGenerated : 2024/03/03 14:33:12
TimeWritten : 2024/03/03 14:33:12
UserName :
Site :
Container :
EventID : 7036
MachineName : WIN201902.test_domain3.test
Data : {115, 0, 112, 0...}
Index : 70151
Category : (0)
CategoryNumber : 0
EntryType : Information
Message : Software Protection サービスは 実行中 状態に移行しました。
Source : Service Control Manager
ReplacementStrings : {Software Protection, 実行中}
InstanceId : 1073748860
TimeGenerated : 2024/03/03 14:32:42
TimeWritten : 2024/03/03 14:32:42
UserName :
Site :
Container :
<以下略>
4. 期間を指定してイベントログを取得する
4.1 指定した日時より後に記録されたログ
実行例: 2023/09/24 00:00:01以降に記録されたログをすべて表示 ※2024/03/03 にコマンド実行
※Afterは指定した時刻は含まないことに注意 (この例では2023/09/24 00:00:01以降のログが表示されます)
PS> Get-EventLog -LogName System -After "2023/09/24 00:00:00"
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
69672 3 03 10:40 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
69670 3 03 10:39 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
69668 3 03 10:38 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
<以下略>
4.2. 指定した日時より前に記録されたログ
実行例: 2024/03/03 23:59:59 以前に記録されたログをすべて表示
※Beforeは指定した時刻は含まないことに注意 (2024/03/02 23:59:59以降のログが表示されます)
PS> Get-EventLog -LogName System -Before "2024/03/03 00:00:00"
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
68404 3 02 23:59 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68402 3 02 23:58 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68401 3 02 23:58 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68400 3 02 23:57 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
<以下略>
4.3. 指定した期間に記録されたログ
実行例: 2023/09/24 00:00:01 ~ 2024/03/03 23:59:59に記録されたログをすべて表示
PS> Get-EventLog -LogName System -After "2023/09/24 00:00:00" -Before "2024/03/03 00:00:00"
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
68404 3 02 23:59 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68402 3 02 23:58 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68401 3 02 23:58 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
68400 3 02 23:57 Information Service Control M... 1073748860 Software Protection サービスは 実行中 状態に移行しました。
<以下略>
5. イベントIDを指定してイベントログを取得する
5.1. 単一のイベントIDを指定
実行例1: イベントID 12のログを抽出
PS> Get-EventLog -LogName System | Where-Object {$_.EventID -eq 12}
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
66870 3 01 13:51 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
66744 3 01 13:51 Information Microsoft-Windows... 12 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '12' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66533 9 24 10:43 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
66417 9 24 10:43 Information Microsoft-Windows... 12 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '12' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66320 9 24 10:40 Information Microsoft-Windows... 12 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '12' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66237 9 24 10:31 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
66125 9 24 10:31 Information Microsoft-Windows... 12 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '12' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66040 9 24 10:23 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
5.2. 複数のイベントIDを指定
複数のイベントIDを指定する場合は括弧でくくり -or 条件を使います。
実行例1: イベントIDが 12 および 13のログを抽出
PS> Get-EventLog -LogName System | Where-Object {($_.EventID -eq 12) -or ($_.EventID -eq 13)}
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
66870 3 01 13:51 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
66744 3 01 13:51 Information Microsoft-Windows... 12 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '12' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66743 9 24 19:47 Information Microsoft-Windows... 13 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '13' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66533 9 24 10:43 Warning Microsoft-Windows... 12 タイム プロバイダー NtpClient: このコンピューターは、ドメイン階層を使ってタイムソースを決定するように構成されていますが、フォレストのルートにあるドメイン用の AD PDC...
6. ソースを指定してイベントログを取得する
PS> Get-EventLog -LogName System -Source Microsoft-Windows-Kernel-General
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
67347 3 02 15:25 Information Microsoft-Windows... 1 CVE の検出の可能性: 2024-03-02T06:25:57.124000000Z...
67205 3 02 09:42 Information Microsoft-Windows... 1 CVE の検出の可能性: 2024-03-02T00:42:29.058000000Z...
67085 3 01 19:18 Information Microsoft-Windows... 1 CVE の検出の可能性: 2024-03-01T10:18:44.395000000Z...
66977 3 01 14:01 Information Microsoft-Windows... 16 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '16' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66974 3 01 14:01 Information Microsoft-Windows... 16 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '16' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
66969 3 01 14:01 Information Microsoft-Windows... 16 ソース 'Microsoft-Windows-Kernel-General' のイベント ID '16' の説明が見つかりません。必要なレジストリ情報またはメッセージを表示するメッセージ DLL ファイルがローカル...
7. ファイルとしてエクスポートする
画面表示ではなくファイルに出力することもできます。
PS> Get-EventLog -LogName System | Export-Csv -Path C:\SystemLog.csv
PS>
文字コードを指定することもできます。ファイルの中身が文字化けする場合は UTF-8 を指定してみましょう。
PS> Get-EventLog -LogName System | Export-Csv -Path C:\SystemLog.csv -Encoding UTF8
PS>
以上。
コメント