Tuesday, 21 July 2020

Search all the Event log for anything in the last 7 days with Powershell

$search = "127.0.0.1"
$Logfiles = Get-WinEvent -ListLog *
Foreach ($i in $Logfiles) {
    Get-WinEvent -FilterHashtable @{logname=$i.LogName; StartTime=(Get-Date).AddDays(-7)} -ErrorAction SilentlyContinue | where-object  { $_.Message -like "*$search*" } | Format-List | Out-File "SearchEvent-$search.txt" -Append
    }

The above script will allow you to search all the events for information and output it too a file, this is handily while looking for information and your not sure which log its held in.

Just change the $search value to what your looking for

No comments:

Post a Comment