Skip to content

Instantly share code, notes, and snippets.

@tkmtmkt
Last active December 11, 2015 04:39
Show Gist options
  • Save tkmtmkt/4547097 to your computer and use it in GitHub Desktop.
Save tkmtmkt/4547097 to your computer and use it in GitHub Desktop.
Windowsイベントログから起動/停止の履歴を抽出する
function Get-RestartLog {
Get-EventLog System |
?{$_.Source -match '(USER32|EventLog)' -and 1074,1076,6005,6006,6008 -contains $_.EventId} | %{
$record = new-object PSObject -property @{
Time = $_.TimeGenerated
EventId = $_.EventId
}
if ($Matches[1] -eq 'USER32') {
$_.Message -split "`r`n" | ?{$_.Length -gt 0} | %{
$line = $_ -split ":(?!\\)",2
if ($line[0] -match "次の理由") {$line[0] = "理由"}
add-member NoteProperty $line[0].trim() -InputObject $record $line[1].trim()
}
} else {
add-member NoteProperty 'コメント' -InputObject $record $_.Message
}
$record
} | select Time,EventId,シャットダウンの種類,理由,理由コード,コメント
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment