gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 01:19 AM |
|
I'm not sure how I would do this could someone assist?
I want to query the eventlogs, write them to a html doc with hyperlinks that take me to eventid.net with the eventid in the url passed.
How the heck would i do that? |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:335

 |
| 29 Sep 2008 02:10 AM |
|
You can use the ConvertTo-Html cmdlet to output everything, but it will filter out any HTML text so it might get sticky. I'm sure it can be done though. I used the Add-Member cmdlet to make a Url field like so:
$events = Get-EventLog -logName system -newest 10
$events | % { $_ | Add-Member -name Url -memberType NoteProperty -value `
"<a target=_blank href=`"http://eventid.net/display.asp?eventid=$( $_.EventId )`">$( $_.EventId )</a>"
} |
|
Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast Author, TechProsaic |
|
|
gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 01:41 PM |
|
Thanks for the reply and the code. When i ran the code nothing came up. Do I need to do anything other than run it? Thanks again. I'm using PowerShell V2 (CTP) |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:335

 |
|
gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 03:55 PM |
|
Ok cool, so at the end of the cmdlet I put $events and I see it output to the console. How do I see the hyperlinks? I didn't see those. |
|
|
|
|
Shay
 Basic Member Posts:281

 |
| 29 Sep 2008 04:02 PM |
|
Try this, it writes the output to an html file and creates the url coulmn as a link.
PS > $events = Get-EventLog -logName system -newest 10
PS > $events | foreach { $_ | Add-Member -name Url -memberType NoteProperty -value "$($_.eventId)" }
PS > $events | convertto-html | foreach {$_.replace("<","<").replace(">",">")} | out-file d:\events.htm
PS > ii d:\events.htm
The code editor renders the link tag, so I attached a file. |
Attachment: 19296590671.txt
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 04:16 PM |
|
WOW! That worked great. Thanks so much. |
|
|
|
|
gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 04:26 PM |
|
Thanks again Shay Just a couple more questions (I am just learning, and appreciate the input) how would i filter so the only thing to show on the html would be URL, EventID (could make these the same?) Event Type, Message, Source, time Generated, Time Written And can we autoformat the output so the cells auto resize? |
|
|
|
|
Shay
 Basic Member Posts:281

 |
| 29 Sep 2008 05:05 PM |
|
See attached file. To autoformat, pipe to format-table, to output to a file pipe to out-file.
|
Attachment: 192951892171.txt
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
gmagerr
 New Member Posts:34

 |
| 29 Sep 2008 05:21 PM |
|
Fantastic, thank you very much. |
|
|
|
|
Shay
 Basic Member Posts:281

 |
| 29 Sep 2008 06:02 PM |
|
You can also extend the event object(s) with a method to navigate to eventid.net for a given event object id: $events = Get-EventLog -logName system -newest 10 $sb = { (new-object -com shell.application).open("http://eventid.net/display.asp?eventid="+$this.eventId) } $events | add-member -type scriptMethod -name FindOnWeb -value $sb # try the first one $events[0].FindOnWeb() |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|
gmagerr
 New Member Posts:34

 |
| 30 Sep 2008 01:41 PM |
|
Shay
Thanks again for all of your help. The last cmdlet seems like it would be useful as well, but this part doesn't work.
# try the first one
$eventsΎ].FindOnWeb() |
|
|
|
|
Shay
 Basic Member Posts:281

 |
| 30 Sep 2008 02:10 PM |
|
Try to replace Ύ] with [ 0 ] (without the spaces)
The post editor don't like these characters combination. |
|
Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic |
|
|