Skip to content

Instantly share code, notes, and snippets.

@jespernohr
Created September 15, 2016 09:18
Show Gist options
  • Save jespernohr/bbf84337abf36e08919ebd05d9f1e3ec to your computer and use it in GitHub Desktop.
Save jespernohr/bbf84337abf36e08919ebd05d9f1e3ec to your computer and use it in GitHub Desktop.
# this powershell code lists all poweroff and restart events from the Windows EventLog
Get-WinEvent -FilterHashtable @{logname='System'; id=1074} | ForEach-Object {
$rv = New-Object PSObject | Select-Object Date, User, Action, Process, Reason, ReasonCode, Comment
$rv.Date = $_.TimeCreated
$rv.User = $_.Properties[6].Value
$rv.Process = $_.Properties[0].Value
$rv.Action = $_.Properties[4].Value
$rv.Reason = $_.Properties[2].Value
$rv.ReasonCode = $_.Properties[3].Value
$rv.Comment = $_.Properties[5].Value
$rv
} | Select-Object Date, Action, Reason, User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment