0
votes

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:

enter image description here

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?

1
what you show is NOT csv format ... it is the powershell display system showing the collection of objects that came from a CSV import. the actual file is just text divided by a delimiter character. - Lee_Dailey
Edited for clarification. - Elmer
you say It looks how I want it too look: and show what powershell shows after you import a CSV ... but that is not a CSV - it is a powershell array created by importing the CSV. ///// you CANNOT make a CSV that looks like that ... it would not be a CSV! [grin] it would only be a plain text file with almost zero structure. - Lee_Dailey
Ok, to rephrase, that's how i want it to look after i use text-to-columns on my CSV. And it doesn't. Everything under 'Execution failed' (see screenshot) should not be in the same column as EventID. - Elmer
kool! now, PLEASE change your Question to say what you actually want. it still refers to wanting a CSV file to look like a plain text report. - Lee_Dailey

1 Answers

1
votes

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

enter image description here