I don't see anything obviously wrong with your script.
Are you using Powershell version 5.1 or the cross platform pwsh.exe?
I added some additional troubleshooting statements. What output does this script produce?
# Define our files.
$xmlPath = "C:\Logs\mghroswl3logins.xml"
$CsvPath = "C:\Logs\mghroswl3logins.csv"
"Powershell version is {0}" -f $PSVersionTable.PSVersion
# Process Custom View XML
"Using XML file {0}" -f $xmlPath
if (Test-Path $xmlPath) {
"I can see the file."
} else {
"File not found!!!"
$folder = Split-Path $xmlPath # pick off the folder name.
"Your XML file is in this folder {0}" -f $folder
if (Test-Path $folder) {
"I can see the folder."
$files = Get-ChildItem $folder -File
"I can see that you have {0} files in that folder." -f $files.count
} else {
"Folder not found!!!!!!!!"
}
return
}
# Load the XML filter
[xml]$xmlFilter = Get-Content $xmlPath
# Get events matching the filter
$events = Get-WinEvent -FilterXml $xmlFilter
"We parsed {0} events." -f $events.count
# Output to CSV
$events |
Select-Object TimeCreated, Id, LevelDisplayName, ProviderName, Message |
Export-Csv $CsvPath -NoTypeInformation -Encoding UTF8