Saturday, May 11, 2019

Powershell: Get-EventLog

Using Get-EventLog cmdlet is sometimes more efficient way to check event log than open Event Viewer.


PS C:\Users\drago> Get-EventLog -LogName System -Newest 5

Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------

12650 5 10 19:02 Information Microsoft-Windows... 1 システムは低電力状態から再開しました。...

12649 5 10 19:02 Information Microsoft-Windows... 1 CVE の検出の可能性: 2019-05-10T10:02:30.5000000..

12648 5 10 19:02 Information EventLog 2147489661 システムの稼働時間は 10367070 秒です。

12647 5 09 23:57 Information Microsoft-Windows... 107 ソース 'Microsoft-Windows-Kernel-Power' のイベ...

12646 5 09 23:57 Information Microsoft-Windows... 42 ソース 'Microsoft-Windows-Kernel-Power' のイベ..



It also can filter logs with '-EntryType' or '-Source'.
I tried to retrieve System Error log other than "DCOM" source type as follow.


PS C:\Users\drago> Get-EventLog -LogName System -EntryType Error | where {$_.Source -notlike "dcom"} | Select-Object -First 5


Index Time EntryType Source InstanceID Message

----- ---- --------- ------ ---------- -------

12355 5 01 14:16 Error Microsoft-Windows... 20 インストールの失敗: エラー 0x80073d02 で次の更...

11835 4 17 13:50 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11834 4 17 13:48 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11833 4 17 13:48 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11765 4 14 20:49 Error Microsoft-Windows... 20 インストールの失敗: エラー 0x80073d02 で次の更...





Here is how we can monitor system event log with retrieving it every 5 seconds.

PS C:\Users\drago> while(1){
>> Get-EventLog -LogName System -Newest 10 ;
>> sleep 5;
>> cls;
>> }

No comments:

Post a Comment