At my company we have a kind of time reporting application. If I book the activities the same day, there is no problem. But after a week, it is not always straightforward to remember what I exactly did on a given day. To have a rough estimate, how many hours I overall and separated for projects worked, I usually make use of data sources like Event Viewer (first and last entries daily in the Windows Logs / System), Exchange (mails sent and receive), Internet Explore (sites visited in Browser History) and TFS (check-ins and task history).
To be able to query the Event Viewer Logs without starting the application and browsing through the entries, I wrote a PowerShell script that perform these tasks automatically for me. It’s nothing extra, but I thought it might be useful for others as well:
$startDay = Get-Date -Date ‘2017/09/01’
$endDay = Get-Date -Date ‘2017/09/11’
$days = New-Object System.Collections.Generic.List“1[System.DateTime]
For ($today = $startDay; $today -le $endDay; $today = $today.AddDays(1)) {
$days.Add($today)
}
$days | % {
$day = $_
$events = Get-EventLog -Log System | ? { $_.TimeGenerated.Date -eq $day.Date }
$maxDate = ($events | Measure-Object -Property TimeGenerated -Maximum).Maximum
$minDate = ($events | Measure-Object -Property TimeGenerated -Minimum).Minimum
select -Input $_ -Prop `
@{ Name=’Day’; Expression={$day.ToShortDateString()} },
@{ Name=’From’; Expression={ $minDate.ToLongTimeString() } },
@{ Name=’To’; Expression={ $maxDate.ToLongTimeString() } },
@{ Name=’Working Hours’; Expression={ $maxDate – $minDate } }
} | Export-Csv -Path C:\Temp\TimeReport.csv -Delimiter ";" -Encoding UTF8 -NoTypeInformation
The script writes the results in a .csv file, but without the last part (Export-Csv) you can direct the output to the screen as well.
