Skip to content

Instantly share code, notes, and snippets.

@rasimmers
Last active September 8, 2016 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasimmers/81a2767e70f0d05066345f15b96c5063 to your computer and use it in GitHub Desktop.
Save rasimmers/81a2767e70f0d05066345f15b96c5063 to your computer and use it in GitHub Desktop.
#Get some data to work with
$procs = Get-Process | Select ProcessName, Id -First 5
#Get the property values of each row using Value
$html = @"
<html>
<body>
$($procs | ConvertTo-Html -Fragment)
</body>
<html>
"@
$finalHTML = $html -replace "<table", "<table border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse;'"
$finalHTML = $finalHTML -replace "<th", "<th border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse; padding:5px;'"
$finalHTML = $finalHTML -replace "<td", "<td border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse; padding:5px;'"
$finalHTML | Out-File "C:\Users\Rob\Desktop\test.html"
Invoke-Item "C:\Users\Rob\Desktop\test.html"
# OR #
$html2 = "<table border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse;>"
foreach ($proc in $procs) {
$html2 += "<tr>"
#Create Header row using the first row and get the Name of the property
foreach ($column in $proc.PSobject.Properties | Select -First 1) {
$html2 += "<td border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse; padding:5px;'>$column.Name</td>"
}
$html2 += "</tr><tr>"
#Create content rows using the Value of properties
foreach ($column in $proc.PSobject.Properties) {
$html2 += "<td border='0' cellspacing='0' cellpadding='0' style='border: 1px solid black; border-collapse: collapse; padding:5px;'>$column.Name</td>"
}
$html2 += "</tr>"
}
$finalHTML | Out-File "C:\Users\Rob\Desktop\test2.html"
Invoke-Item "C:\Users\Rob\Desktop\test2.html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment