I was looking at getting error event logs from the previous day, when looking at the different post on the forums I come across different day/time PowerShell formats that range from a specific date. I was looking at this PowerShell format for a date
Example 11: Get all errors in an event log that occurred during a specific time frame
I was wondering what would be the correct way to have this PowerShell search for errors from the previous day, so if its run on Tuesday it will gather all Mondays, Friday will gather all Thursdays. This is how I started doing it with no success.
You may want to do it slightly differently if you want "the previous day" as opposed to "the previous 24 hours precisely" (which would be from the current time to the same time the previous day):
$Today = (Get-Date).Date # Removes the hour/minute/second and anchors on the start of the day
$Yesterday = $Today.AddDays(-1)
Get-EventLog -Log System -EntryType Error, Warning -Before $Today -After $Yesterday
The topic ‘Date Log Question’ is closed to new replies.