Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Get the active time from Eventlog, login event.
#Initialize
$Weekday=@("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
$LoginData=@{}
ForEach($w in $Weekday){
$LoginData[$w]=@{}
0..23 | % {$LoginData[$w][$_]=0}
}
#Get the data from Eventlog
$i=0
Get-EventLog -LogName Security | Where EventID -Eq 4624 | Select TimeGenerated | % {
$d=([DateTime]($_.TimeGenerated)).DayOfWeek
$h=([DateTime]($_.TimeGenerated)).Hour
$LoginData[([String]$d)][$h]+=1
$i++;Write-Host "Calculating:"$i
}
#Show weekday vs hour table
&{
Write-Host "[Hour]`t" -n
ForEach($w in $Weekday){
Write-Host $w.SubString(0,3)`t -n
}
Write-Host
ForEach($h in (0..23)){
Write-Host $h -n
ForEach($w in $Weekday){
Write-Host `t $LoginData[$w][$h] -n
}
Write-Host
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment