Last active
September 8, 2016 16:58
-
-
Save rasimmers/81a2767e70f0d05066345f15b96c5063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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