Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Clear an event log with specific ID using Powershell

$
0
0

Hi,

I need to do a search in system or security logs and find a special ID log (for example event id : 1022) and clears all of those logs

i tested

Get-EventLog "System" | Where-Object {$_.EventID -eq 16397}

and

Get-WinEvent "System" | Where-Object {$_.EventID -eq 16397}

but did not work, (Get Works but clear makes the below error) seems logs are not sent to these commands as separate identities

PS C:\> Get-EventLog "System" | Where-Object {$_.EventID -eq 16397}  | Clear-EventLog
Clear-EventLog : Object reference not set to an instance of an object.
At line:1 char:78
+ Get-EventLog "System" | Where-Object {$_.EventID -eq 16397}  | Clear-EventLog <<<<
    + CategoryInfo          : NotSpecified: (:) [Clear-EventLog], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.ClearEventLogCommand


Payne is back


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>