Reputation: 398
I have a script that exports evens from the eventlog like:
Get-EventLog -LogName Application | Where-Object Source -Match "my application" | export-csv "$FileDate.csv"
When I open the CSV it does not look how I want it too. It shows
EventID,"MachineName","Data","Index","Category","CategoryNumber","EntryType","Message","Source","ReplacementStrings","InstanceId","TimeGenerated","TimeWritten","UserName","Site","Container" 0,"DESKTOP-ID94AN3","System.Byte[]","21425","(0)","0","Error","Finished executing project 'Testproject' Execution Package 'Failure' Execution failed Start Time : 21/12/2020 19:47:52 End Time : 21/12/2020 19:47:56 on server: DESKTOP-ID94AN3 -Logmessage
After text-to-columns:
With information in columns where it should not be. It seems to combine the 2 windows from the event viewer. The 'upper' window with the errors and the 'lower' window with the details. All I want is the upper window.
If I run this code in Windows Powershell ISE:
Get-EventLog -LogName Application | Where-Object Source -Match "Myapplication"
It looks how I want it too look (after using text to columns):
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
21425 Dec 21 19:47 Error Myapplication LogEn... 0 Message 1
21424 Dec 21 19:47 Information Myapplicationr LogEn... 0 Message 2
How do I get my CSV export to look like this also?
Upvotes: 0
Views: 240
Reputation: 13537
You can make it look the way you want by selecting only the specific columns you care about, before sending the results over to Export-CSV
.
Get-EventLog -LogName Application | Where-Object Source -Match "edgeupdate" |
Select -first 10 -Property Index, Time, EntryType, Source, InstanceId, Message |
Export-Csv -NoTypeInformation
Upvotes: 1