Array to HTML

rated by 0 users
This post has 8 Replies | 2 Followers

Top 500 Contributor
Posts 8
Rafiki Posted: 04-19-2012 11:40 AM

I am creating an array from the data collected from the different sources and trying to covert array to HTML. It works if the source is .NET object and does not for created array. Any thoughts?

$DataIN = @{“User Name” = “John Doe”; “Computer Name” = "MyWorkstation"; “Serial Number” = "334455"}
$MessInfo1 = $EmpNumbers | ConvertTo-HTML
$MessInfo1 | Out-File "$PWD\MessInfo.html"
Invoke-Expression "$PWD\MessInfo.html"

Top 10 Contributor
Posts 640

So, what doesn't work?

That is, I'm not sure what you were expecting, vs. what you got.

Note that in your example, you've put data into $DataIN, but it's $EmpNumbers you're converting to HTML. Based strictly on your snippet, $EmpNumbers is empty.

There's also no need for $MessInfo1.

$DataIN | ConvertTo-HTML | Out-File whatever.html

Top 500 Contributor
Posts 8

Sorry.

Did not cleaned up:

I am creating an array from the data collected from the different sources and trying to covert array to HTML. It works if the source is .NET object and does not for created array. Any thoughts?

$DataIN = @{“User Name” = “John Doe”; “Computer Name” = "MyWorkstation"; “Serial Number” = "334455"}
$MessInfo1 = $DataIN | ConvertTo-HTML
$MessInfo1 | Out-File "$PWD\MessInfo.html"
Invoke-Expression "$PWD\MessInfo.html"

Top 25 Contributor
Posts 287
Top Contributor

You are using a hash table and not an array.

Try:

$DataIN = @{“User Name” = “John Doe”; “Computer Name” = "MyWorkstation"; “Serial Number” = "334455"}

foreach($_ in $DataIN.keys){ConvertTo-HTML -Body $_,$DataIN.$_ >> "$PWD\MessInfo.html"}

Invoke-Expression "$PWD\MessInfo.html"

Top 500 Contributor
Posts 8

Thank you.

It is close to what I am trying to accomplish. Can it be done without saving to disk?

Top 25 Contributor
Posts 287
Top Contributor

$DataIN = @{“User Name” = “John Doe”; “Computer Name” = "MyWorkstation"; “Serial Number” = "334455"}

$IE=new-object -com internetexplorer.application

$IE.navigate2("About:blank")

$body = $IE.document.documentelement.lastchild

$body.innerhtml = foreach($_ in $DataIN.keys){ConvertTo-HTML -Body $_,$DataIN.$_ }

$IE.visible = $true

 

Top 500 Contributor
Posts 8

Normal 0 false false false EN-US X-NONE X-NONE

Thanks a lot. It works. But let me explain what I am trying accomplish. I’d like to email hash table as a body of the message to make it look nicer. Does it make sense?

send-Mailmessage –to …… -body $DataIN -BodyAsHtml

Top 25 Contributor
Posts 287
Top Contributor

You have to convert it to HTML before you pass it to Send-MailMessage if you are going to use the -BodyasHtml switch..

$DataIN = @{“User Name” = “John Doe”; “Computer Name” = "MyWorkstation"; “Serial Number” = "334455"}

$body = foreach($_ in $DataIN.keys){ConvertTo-HTML -Body $_,$DataIN.$_ }

Send-MailMessage -to ... -body $body -BodyAsHtml

 

Top 500 Contributor
Posts 8

Yep. This what I am trying to do.

Page 1 of 1 (9 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.