Is there a way to search through all event file logs in a folder?

I’ve tried the following code but it didn’t seem to work

$EventLogonIDs="4720"Get-WinEvent -FilterHashtable @{Path="C:\windows\system32\winevt\Logs\Security*.evtx";id= @($EventLogonIDs);StartTime="1/1/2017";EndTime="1/8/2023"} | Export-Csv c:\result.csv

4 Spice ups

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

Done and thanks for that!

It depends on what OS and what you are trying to do ??

You can easily set custom views to see only the events that occur OR you can set filters to filter out certain events.

Your code seems to work just fine.

Do you run powershell as admin? that’s needed for powershell to get access to the eventlogs

you will need to try something like

Get-ChildItem -include *.evt,*.evtx -Path C:\windows\system32\winevt\Logs\Security -recurse |

ForEach-Object {

"Parsing $($_.fullname)`r`n"

Try

{ Get-WinEvent -FilterHashtable @{

Path=$_.fullname

ID=4720;

StartTime="1/1/2017" ;

EndTime="1/8/2023"} -EA Stop}

Catch [System.Exception] {"No errors in current log"}

}

A small thing - the Spiceworks editor has mangled your code. Can you RE-edit it??

Also, as a general rule “the code does not work” is not helpful to me to work out what might be going wrong. Please consider posting the exact error message. It turns out that PowerShell error messages are pretty good but sometimes confusing given all the red ink. PowerShell 7 is a lot better in this respect.