I have quite a usual for every sysadm in task: to audit access to certain folders on fileserver during last, e.g. 1 day. But in addition I need to rule out access attempts from certain processes.
What I wrote (part of code:
foreach ($FileServer in $Fileservers) {
Write-Host -ForegroundColor Green "Checking events on $FileServer"
$GweParams = @{
Computername = $Fileserver
LogName = ‘Security’
FilterXPath = '*[System[EventID=4656 or EventID=4663]
and not (EventData[Data[@Name='ProcessName'] = 'C:\Windows\System32\fsdmhost.exe'])
and TimeCreated[timediff(@SystemTime) <= 360000]]'
}
$Events = Get-Eventlog @GweParams
$Events
$Events | export-csv -path C:\usr\logs.csv
}
But Powershell gives me plenty of errors, and even more, ISE visually splitting this code in quite unexpected blocks. It seems to me that I am missing some of quotes and brackets, but can't figure out where?
Could somebody help me with this? Or suggest some better code?
Taking Event ID 4656 as an example from your code, it looks like there is a specific field with process information. You can just filter out the events based on the process name such as :
Assuming the property available is called "Process". I don't have access to an example of this specific ID, but you can provide one like this
Do not forget to remove any sensitive / PII info before answering. Happy to follow up after that