Windowsのイベントログから指定したものだけ抜き出せる、
eventquery.vbs
は、WindowsServer2008以降は使えません。
1)まずは打ってみましょ。
Get-EventLog -list
PS C:> Get-EventLog -list
Max(K) Retain OverflowAction Entries Log
------ ------ -------------- ------- ---
20,480 0 OverwriteAsNeeded 6,488 Application
20,480 0 OverwriteAsNeeded 0 HardwareEvents
512 7 OverwriteOlder 0 Internet Explorer
20,480 0 OverwriteAsNeeded 0 Key Management Service
20,480 0 OverwriteAsNeeded 4,292 Security
20,480 0 OverwriteAsNeeded 8,908 System
15,360 0 OverwriteAsNeeded 172 Windows PowerShell
PS C:>
2)ログの詳細を見る場合
ログには
・Application
・HardwareEvents
・Internet Explorer
・Key Management Service
・Security
・System
・Windows PowerShell
があることが分かりました。
その中でもシステムログを見てみます
ログ・・・・・・・・・・System
オプション・・・・・LogName
(止めるときはCtrl+C)
PS C:> Get-EventLog -LogName System
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
8917 1 07 18:47 Information Service Control M... 1073748860 WinHTTP Web Proxy Auto-Discovery Service サービ...
8916 1 07 18:41 Information Service Control M... 1073748860 Application Experience サービスは 停止 状態に移...
8915 1 07 18:31 Information FcsSas 1073882897 セキュリティ状態の評価スキャンは正常に終了しま...
8914 1 07 18:31 Information Microsoft-Windows... 19 インストールの成功: 次の更新プログラムが正しく...
・
・
・
PS C:>
これだと見難いので、
オプション・・・・・Format-List *
(止めるときはCtrl+C)
PS C:> Get-EventLog -LogName System | Format-List *
EventID : 7036
MachineName : Hogehoge
Data : {87, 0, 80, 0...}
Index : 8908
Category : (0)
CategoryNumber : 0
EntryType : Information
Message : Portable Device Enumerator Service サービスは 停止 状態に移行しました。
Source : Service Control Manager
ReplacementStrings : {Portable Device Enumerator Service, 停止}
InstanceId : 1073748860
TimeGenerated : 2010/01/07 16:40:19
TimeWritten : 2010/01/07 16:40:19
UserName :
Site :
Container :
・
・
・
PS C:>
エントリが「EntryType」に「エラーレベル」があることが分かります。
他には、「EventID」を良く見ますね。
3)例として「Error」だけ抜き出します
「システムログ」の中で「Error」だけを抜き出します。
(ログが多いと大変時間がかかります。)
ログ・・・・・・・・・・System
エントリ・・・・・・・EntryType
エラーレベル・・・Error
オプション・・・・・Where {$_.エントリ -eq “一致する文字列” }
補足
Error・・・・・・エラー
Warning・・・・・警告
Information ・・情報
SuccessAudit ・・成功した監査
FailureAudit ・・失敗した監査
(止めるときはCtrl+C)
PS C:> Get-EventLog -LogName System | Where {$_.EntryType -eq "Error" } | Format-List *
EventID : 56
MachineName : Hogehoge
Data : {0, 0, 4, 0...}
Index : 8854
Category : (0)
CategoryNumber : 0
EntryType : Error
Message : ターミナル サーバーのセキュリティ層で、プロトコル ストリームにエラーが検出され、クライアントが切断
されました。
クライアント IP: ***.***.***.***。
Source : TermDD
ReplacementStrings : {DeviceTermdd, ***.***.***.***}
InstanceId : 3221880888
TimeGenerated : 2010/01/06 12:38:29
TimeWritten : 2010/01/06 12:38:29
UserName :
Site :
Container :
・
・
・
PS C:>
このエラーはリモートデスクトップを通常切断しなかった時のエラーです。
4)日付で絞り込む
今までのやり方だと時間はかかるし大変です。
今度は、1週間前までで「System」の中で「Warning」だけを抜き出します。
(ログが多いと大変時間がかかります。)
期間・・・・・・・・・・過去7日間
ログ・・・・・・・・・・System
エントリ・・・・・・・Timegenerated
エラーレベル・・・Warning
オプション・・・・・where {$_.Timegenerated -gt (get-date).AddDays(-日数)}
補足
(get-date).AddHours(-時間)
(get-date).AddMilliseconds(-ミリ秒)
(get-date).AddMinutes(-分)
(get-date).AddMonths(-月)
(get-date).AddSeconds(-秒)
(get-date).AddTicks(-タイマ刻み数)
(get-date).AddYears(-年)
(止めるときはCtrl+C)
PS C:> Get-EventLog -LogName System | Where {$_.EntryType -eq "Warning"} | Where {$_.timegenerated -gt (get-date).AddDays(-7)} | Format-List *
EventID : 1002
MachineName : Hogehoge
Data : {}
Index : 8664
Category : (0)
CategoryNumber : 0
EntryType : Warning
Message : %Microsoft Forefront Client Security スキャンは完了する前に停止しました。
スキャン ID: {******************}
スキャンの種類: %マルウェア対策ソフトウェア
スキャン パラメータ: %クイック スキャン
ユーザー: hogehohehogehoge
Source : FCSAM
ReplacementStrings : {******************}
InstanceId : 1002
TimeGenerated : 2010/01/04 20:22:35
TimeWritten : 2010/01/04 20:22:35
UserName :
Site :
Container :
・
・
・
PS C:>
あははは~~
Forefront Client Securityのスキャンを途中で止めたのが分かりますね。
[tegaki]タブ補完が良い!![/tegaki]