2

#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: , ,

2 Responses to "#PSTip How to convert .NET Framework objects into HTML"

  1. Peter Kriegel says:

    Thank you Aleksandar, very useful!
    It is even suprisingly easy to convert a .NET Datatable to CSV!

    $ds = New-Object System.Data.DataSet
    $da.Fill($ds) >$null| Out-Null
    $ds.Tables[0] | export-csv tofile.csv -notypeinformationhttp://stackoverflow.com/questions/10149910/use-powershell-to-save-a-datatable-as-a-csvPeter Kriegelhttp://www.admin-source.de

  2. Ravikanth says:

    Thanks Alex! Quite useful.

Leave a Reply

Submit Comment

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