header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

How would i add a hyperlink
Last Post 30 Sep 2008 02:10 PM by Shay. 12 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
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?



halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:335
Avatar

--
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
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
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)



halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:335
Avatar

--
29 Sep 2008 02:20 PM  
Oh, sorry, I should have added a "$events" to the end. It worked, but it didn't output the variable, that's all.


Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
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.


ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
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
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
29 Sep 2008 04:16 PM  
WOW! That worked great. Thanks so much.


gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
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?


ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
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
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
29 Sep 2008 05:21 PM  
Fantastic, thank you very much.


ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
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
gmagerrUser is Offline
New Member
New Member
Posts:34
Avatar

--
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()



ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
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
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer