Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embed a picture <img> in convertto-html

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hello all,
I was wondering if I could embed a picture from a url in a ps1 script. I want to use Google graphing api, so I want to embed this graph
Code:
[URL unfurl="true"]http://chart.apis.google.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World[/URL]

like this
Code:
$filelocation = "C:\testscript\pwrshl\asshat.html"
$a = @("Rim","Rob")
$s = "" | Select f, l, e
$s.f = "Tim" 
$s.l = "Gallagher"
$s.e = "tim@g.com"
$s1 = "" | Select f, l, e
$s1.f = "Michelle"
$s1.l = "Gallagher"
$s1.e = "Michelle@danati.com"
$a = @()

$a += $s
$a += $s1

$a | Select-Object |   ConvertTo-Html  -Title "Services" -Body "<H2>My Array</H2> "  -head "<linkrel='stylesheet' href='asshat.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html  -Title "Services" -Body "<img [URL unfurl="true"]http://chart.apis.google.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World[/URL] />" | Out-File -Append $filelocation


Thanks for the help,
timgerr


-How important does a person have to be before they are considered assassinated instead of just murdered?
Congratulations!
 
Are you getting errors when you try to do this? Or what kind of problem are you having with it?
 
Sorry I have been out, I just want to insert this png into a html file from Powershell.

Tim

-How important does a person have to be before they are considered assassinated instead of just murdered?
Congratulations!
 
First, I'd upgrade to PowerShell v2. They've added some parameters to ConvertTo-HTML that make this a little easier. Your example then becomes:
Code:
$filelocation = "C:\temp\test.html"

$chart1 = @"
<img src="[URL unfurl="true"]http://chart.apis.google.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World">[/URL]
"@

$a = @()
$s = "" | Select-Object f, l, e
$s.f = "Tim"
$s.l = "Gallagher"
$s.e = "tim@g.com"
$a += $s

$s = "" | Select-Object f, l, e
$s.f = "Michelle"
$s.l = "Gallagher"
$s.e = "michelle@danati.com"
$a += $s

$a | ConvertTo-Html -Title "Services" -Body "<H2>My Array</H2>" -CssUri "style1.css" -PostContent $chart1 | Out-File $filelocation

Doing it in v1 would probably involve constructing several strings and outputting them, or would require editing the HTML file after the fact to remove some extraneous code if you used multiple ConvertTo-HTML statements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top