Skip to content

Instantly share code, notes, and snippets.

@kkamegawa
Created December 13, 2014 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkamegawa/4b132328de59f79c4d5f to your computer and use it in GitHub Desktop.
Save kkamegawa/4b132328de59f79c4d5f to your computer and use it in GitHub Desktop.
Show working time in office. I checked Vista, and Windwos 7.
$date = [datetime]::today.adddays(-1)
$events = Get-EventLog -LogName system -before $date | where-object {$_.source.startswith("Microsoft-Windows-Kernel") -eq $true -or $_.source.startswith("Microsoft-Windows-Power") -eq $true} | select-object timegenerated,source,InstanceID
$poweron = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-General" -and $_.InstanceID -eq 12}
$shutdown = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-General" -and $_.InstanceID -eq 13}
$sleepwakeup = $events | where-object {$_.source -eq "Microsoft-Windows-Power-Troubleshooter" -and $_.InstanceID -eq 1}
$sleepgo = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-Power" -and $_.InstanceID -eq 42}
$workend = $shutdown[0].TimeGenerated
if($sleepgo -ne $null) {
if($shutdown[0].TimeGenerated -lt $sleepgo[0].TimeGenerated) {
$workend = $sleepgo[0].TimeGenerated
}
}
$workstart = $poweron[0].TimeGenerated
if($sleepwakeup -ne $null) {
if($sleepwakeup[0].TimeGenerated -lt $poweron[0].TimeGenerated) {
$workstart = $sleepwakeup[0].TimeGenerated
}
}
write-host 前日の勤務はたぶん $workstart から $workend です。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment