Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Last active January 7, 2016 06:45
Show Gist options
  • Save midnightfreddie/0a0c29d955e5a6b0db8a to your computer and use it in GitHub Desktop.
Save midnightfreddie/0a0c29d955e5a6b0db8a to your computer and use it in GitHub Desktop.
$Data = 1..10 | ForEach-Object {
New-Object psobject -Property ([ordered]@{
Col1 = (Get-Random -Maximum 1000) + 1
Col2 = (Get-Random -Maximum 1000) + 1
Col3 = (Get-Random -Maximum 1000) + 1
Col4 = (Get-Random -Maximum 1000) + 1
Col5 = (Get-Random -Maximum 1000) + 1
})
}
$Body = @"
<style>
th { background-color: yellow; }
td:nth-child(2) { background-color: green; }
td:nth-child(3) { color: red; }
td:nth-child(4) { font-weight: bold }
</style>
<div>This is the body content</div>
"@
$Pre = @"
<div>This is the pre-table content</div>
"@
$Post = @"
<div>This is the post-table content</div>
"@
$Data |
ConvertTo-Html -Body $Body -PreContent $Pre -PostContent $Post -Title "TITLE!" |
Out-File -Encoding utf8 -FilePath ".\out.html"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TITLE!</title>
</head><body>
<style>
th { background-color: yellow; }
td:nth-child(2) { background-color: green; }
td:nth-child(3) { color: red; }
td:nth-child(4) { font-weight: bold }
</style>
<div>This is the body content</div>
<div>This is the pre-table content</div>
<table>
<colgroup><col/><col/><col/><col/><col/></colgroup>
<tr><th>Col1</th><th>Col2</th><th>Col3</th><th>Col4</th><th>Col5</th></tr>
<tr><td>673</td><td>648</td><td>942</td><td>580</td><td>576</td></tr>
<tr><td>774</td><td>838</td><td>972</td><td>675</td><td>614</td></tr>
<tr><td>172</td><td>686</td><td>369</td><td>758</td><td>193</td></tr>
<tr><td>679</td><td>214</td><td>125</td><td>829</td><td>613</td></tr>
<tr><td>304</td><td>172</td><td>529</td><td>30</td><td>770</td></tr>
<tr><td>457</td><td>784</td><td>316</td><td>620</td><td>732</td></tr>
<tr><td>557</td><td>995</td><td>658</td><td>430</td><td>894</td></tr>
<tr><td>46</td><td>184</td><td>561</td><td>598</td><td>858</td></tr>
<tr><td>914</td><td>393</td><td>751</td><td>618</td><td>920</td></tr>
<tr><td>769</td><td>782</td><td>810</td><td>604</td><td>761</td></tr>
</table>
<div>This is the post-table content</div>
</body></html>
@midnightfreddie
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment