I'm using the following to save a CSV file of output from Event Logs on several Windows Servers:
Get-EventLog -LogName $logName -ComputerName $servers -Newest 2 -Entry 'Error', 'Warning' -ErrorAction SilentlyContinue | Sort MachineName, TimeWritten | Select MachineName, Source, TimeWritten, EventID, EntryType, Message | Export-CSV $csvFile #ConvertTo-CSV #Format-Table -Wrap -Property Source, TimeWritten, EventID, EntryType, Message -Autosize |
I then remove the first line (as it starts with #Type and is unneeded!):
$file = Get-Content $csvFile
$file[1..($file.length-1)] | Out-File $csvFile -Encoding ascii
When opened in Excel, it isn't formatted very nice. I'd like to convert this to Excel and format the cells to fit contents, change font size.
Can this be done from within my script?