Link to home
Start Free TrialLog in
Avatar of c7c4c7
c7c4c7Flag for United States of America

asked on

how to create a powershell report for the event log using convertto-html

I am trying to convert the output of a powershell script to HTML but I'm having problems with the output of the Group-Object commandlet.  It's giving me output that junks up the display and I can't figure how to get rid of it.

The original commandlet and the convertto-html  is in the attachment.  I want to get rid of the Value and Group Column.

Also please explain why your answer gets rid of the unwanted columns


Thanks for the help
convertohtml.txt
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use Select-Object (Select) to filter the properties..

For example..
$events = Get-Eventlog -logname system -EntryType Error -After ((Get-Date).Date.AddDays(-1))
$events | Group-Object -property source -noelement | Select Count,Name | Sort-Object -property count -descending |  convertto-html > c:\logs\new.html

Open in new window

By default the Group-Object cmdlet only displays the Count and Name properties, but ConvertTo-HTML works on all the properties passed to it.  By using the Select-Object cmdlet we can limit which properties to pass on.
Use this
$events = Get-Eventlog -logname system -EntryType Error -After ((Get-Date).Date.AddDays(-1))
$events | Group-Object -property source -noelement | Sort-Object -property count -descending |  ConvertTo-HTML count,name | Out-File c:\temp\new.html

Let me know, if that helps
Avatar of c7c4c7

ASKER

Thanks for the help