#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

About the author: Aleksandar Nikolic

Aleksandar is a PowerShell MVP and a co-founder of PowerShell Magazine. He is a frequent speaker at the conferences and participates regularly in IT Pro user groups worldwide. Recently, Aleksandar co-authored the highly respected Administrator’s Guide to Windows PowerShell Remoting. Follow him on Twitter at @alexandair

Related Posts

%d bloggers like this: