henrydenhengst

logon time windows

Nov 3rd, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $UserProperty = @{n="User";e={(New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
  2. $TypeProperty = @{n="Action";e={if($_.EventID -eq 1000) {"Logon"} else {"Logoff"}}}
  3. $TimeProperty = @{n="Time";e={$_.TimeGenerated}}
  4. $MachineNameProperty = @{n="MachinenName";e={$_.MachineName}}
  5. $logontime = Get-EventLog System -Source TdIca | select $UserProperty,$TypeProperty,$TimeProperty,$MachineNameProperty
  6. if ($logontime.Length -ne $null) { $logontime = $logontime[0] }
  7. # explorer might not give the right results back, sometimes something else
  8. # that you start off from boot might give better results, like lync etc
  9. $explorer = Get-Process | where { $_.name -eq "explorer"} | select name, starttime
  10. write-host $logontime.Time
  11. write-host $explorer.StartTime
  12. (NEW-TIMESPAN –Start $logontime.Time –End $explorer.StartTime).TotalSeconds
Advertisement
Add Comment
Please, Sign In to add comment