1

I've got the below

Get-EventLog -LogName * -After (Get-Date).Adddays(-7)

Which returns the information I require:

Event log return

Now when I export this information out with

Export-Csv c:\temp\$([Environment]::MachineName).csv

It returns the following under the entries section in my CSV:

System.Diagnostics.EventLogEntryCollection 

I will be running this on multiple servers and collecting all logs into one area.

So Now I have changed the information to be a bit more specific

Get-EventLog -LogName * -After (Get-Date).Adddays(-7) |
  Select-Object MachineName, Log, Entries |
  Export-Csv -NoTypeInformation c:\temp\$([Environment]::MachineName).csv 

This now returns the below when I'm exporting out to a CSV:

New Export

But I can't see the amount of entries I require. Is there a work around for this?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Phil Skinner
  • 45
  • 1
  • 5

2 Answers2

1

The Entries property contains a collection. You need the Count of that collection. You may also want to replace the MachineName value (. for the local computer) with the actual computer name. Calculated properties are the usual way to achieve this:

Get-EventLog -LogName * -After (Get-Date).Adddays(-7) |
  Select-Object @{n='MachineName';e={$env:COMPUTERNAME}}, Log,
                @{n='Entries';e={$_.Entries.Count}} |
  Export-Csv "C:\temp\$env:COMPUTERNAME.csv" -NoType
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

Use the -NoTypeInformation switch parameter to omit the type header:

$data | Export-Csv C:\temp\$([Environment]::MachineName).csv -NoTypeInformation
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • It still returns the System.Diagnostics.EventLogEntryCollection on the entries column, is this because it's the first column within the CSV? – Phil Skinner Dec 30 '15 at 10:32