0

#PSTip Use Excel to View HTML Output

Excel can be used to view HTML.  If you add some CSS styles to the result of ConvertTo-HTML you can add much more rich output to Excel then you would get with a simple Export-Csv

$HTMLFile = Join-Path $Home "Processes.html"
$HTML = Get-Process | Select-Object CPU, ID, ProcessName | ConvertTo-HTML

# Reference for color names http://www.w3schools.com/cssref/css_colornames.asp
$HTML = $HTML -replace '^[<]tr[>][<]td[>][<][/]td[>]','<tr style="color:red" ><td></td>'

# Highlight anything that has Chrome or Google In the Name
$HTML = $HTML -replace '[<]td(?<T>[>]((chrome)|(Google[^<]*))[<][/]td[>])','<td style="background:blue;color:Yellow" ${T}'
$HTML | Out-File $HTMLFile 

#Find a good version of Excel.exe
$Excel = Resolve-Path "C:\Program Files*\Microsoft Office\Office*\EXCEL.EXE" | 
            Select-Object -First 1 -ExpandProperty Path  

& $Excel $HTMLFile 

excelcolor

Filed in: Columns, Tips and Tricks Tags: , ,

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: