Windows – Clean up event log by script

windowswindows-event-log

Any way to remove all entries from the Windows event logs (Application, System & Software) apart from the last 24 hours?

Via command line such as batch file.

On Windows 2008 R2 Server & Windows 7

Best Answer

You can't do what you are trying to do. You can either save or clear an event log. When you clear, you can optionally save the events before clearing.

EDIT

Looking again, that wasn't very helpful. You can't remove some events from an event log without removing them all. You can, however, export some events based on a filter. For example, the following command will export all events logged to the System event log in the last 24 hours:

wevtutil epl system c:\system.evtx /q:"*[System[TimeCreated[timediff(@SystemTime) <= 86400000]]]"

Does this get closer to what you want? If not, can you clarify if there is something more we can help with?