Normally I can open the Computer Management console, go to the Event Viewer snap-in, open the Windows Logs folder, right-click on Application/Security/Setup/System
subfolder, choose Clear Log and confirm by pressing the Clear
or Save and Clear
button.
Having enough rights, how can I achieve the same effect through using command line, while raising no confirmation requests?
Powershell.
The default is not to prompt you, but you can supply the -Confirm switch if you want to be prompted.
Edit:
As per the comments, that should get both Operational and Administrative logs.
wevtutil enum-logs
will enumerate all logs in the system whilewevtutil clear-log
will clear the logs. For your case it would be:You can also backup while clearing with
wevtutil clear-log System /backup:backup.evtx
For the case you want to clear all logs:
Extracted from here.
The following PowerShell clears all the event logs on the local machine, including the operational/debug/setup logs programmatically (without instantiating the "wevtutil" process). To clear just one log, modify the code accordingly. It's not perfect, however, sometimes the Debug logs are held open by something, and this does not generate any errors.
this is how to clear all event log through powershell, make sure you're running it as administrator
wevtutil el | Foreach-Object {wevtutil cl "$_"}