#PSTip How to convert .NET Framework objects into HTML

The ConvertTo-Html cmdlet converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser. In the following example we pick up a few properties of process objects with name that contains the word ‘host’, sort the output by the ‘Handles’ property, convert it to HTML, and save it as HTML file in the user’s TEMP folder. At the end we open the HTML file in the default browser.

Get-Process -Name *host* |
Select-Object -Property Name,Id,Handles |
Sort-Object -Property Handles -Descending |
ConvertTo-Html -Title "PowerShell Rocks!" -Body "<h1>Info about *host* processes</h1>" |
Out-File -FilePath $env:TEMP\processes.html

Invoke-Item -Path $env:TEMP\processes.html
Filed in: Columns, Tips and Tricks Tags: , ,
© 2018 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: