Advertisement
Yunga

Get-SleepInfo.ps1

May 13th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param($Newest = 50)
  2.  
  3. function Parse-EventLogEntry
  4. {
  5.     param(
  6.         [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
  7.         [System.Diagnostics.EventLogEntry[]]
  8.         $eventInfo
  9.     )
  10.  
  11.     Process
  12.     {
  13.         foreach ($info in $eventInfo)
  14.         {
  15.             $enterSleep = [DateTime]::Parse($info.ReplacementStrings[0]);
  16.             $exitSleep = [DateTime]::Parse($info.ReplacementStrings[1]);
  17.             $duration = $exitSleep - $enterSleep
  18.             $wakeSource = 'Unknown'
  19.             if ($info.Message -match 'Wake Source:\s*(.*)$')
  20.             {
  21.                 $wakeSource = $matches[1]
  22.             }
  23.             new-object psobject -Property @{Duration = $duration; Sleep = $enterSleep;
  24.                                             Wake = $exitSleep; WakeSource = $wakeSource}
  25.         }
  26.     }
  27. }
  28.  
  29. Get-EventLog -LogName System -Source Microsoft-Windows-Power-Troubleshooter -Newest $Newest | Sort TimeGenerated | Parse-EventLogEntry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement