Afternoon all. I’m trying to sort out a script that gives me a daily CSV of the System Errors on a number of servers.
I found a good script that I’ve been modifying for my needs, but have hit a bit of a snag at the last step.
First of all, here is the script:
Set-Variable -Name EventAgeDays -Value 1 #events from the last 1 day Set-Variable -Name CompName -Value @("APP1", "APP2", "APP3", "APP4") #Server names Set-Variable -Name LogNames -Value @("System") # Checking system logs Set-Variable -Name EventTypes -Value @("Error") # Loading only Errors Set-Variable -Name ExportFolder -Value "C:\TEST\" #Folder to export CSV file to $el_c = @() #consolidated error log $now=get-date $startdate=$now.adddays(-$EventAgeDays) $ExportFile=$ExportFolder + "Error Log" + $now.ToString("yyyy-MM-dd---hh-mm-ss") + ".csv" foreach($comp in $CompName) { foreach($log in $LogNames) { Write-Host Processing $comp\$log $el = get-eventlog -ComputerName $comp -log $log -After $startdate -EntryType $EventTypes $el_c += $el #consolidating } } $el_sorted = $el_c | Sort-Object MachineName, TimeGenerated #sort by time Write-Host Exporting to $ExportFile $el_sorted | Group-object -Property "source", "MachineName" | Select-Object -Property Count, Name | export-csv $ExportFile -NoTypeInformation Write-Host Done!
Now, the issue is that when I run this it exports the CSV as follows:
"Count","Name" "2","Ntfs, APP1" "1","TermDD, APP1" "117","Schannel, APP2" "2","Ntfs, APP2" "1","TermDD, APP2" "12","TermServDevices, APP2" "12","TermServDevices, APP3" "1","DCOM, APP3"
The Problem is that because of the grouping it is exporting only 2 columns and the error type and server name are in the same one, but I want those two in separate columns so it is easier to work with.
I’ve been trying every combination I can think of to make this work, but failing miserably! Can anyone help?