Create an HTML page from one or more powershell objects.
Syntax
ConvertTo-Html [[-property] Object[] ]
[-inputObject psobject]
[-body string[] ] [-head string[] ] [-title string]
[CommonParameters]
key
-inputObject psobject
The objects to represent as an HTML table.
A variable that contains the objects or a command/expression
that gets the objects.
-property Object
Properties of the input object to appear in the HTML table.
-body string
Text to include in the <body> element of the HTML.
-head string
Text to include in the <head> element of the HTML output.
-title string
Text to include in the <title> element of the HTML output.
CommonParameters
The common parameters: -Verbose, -Debug,-ErrorAction, -ErrorVariable, -OutVariable
The object property names appear as HTML table column headings.
Examples
Display the date as HTML on the console :
PS C:\>get-date | convertto-html
Save the system processes to C:\processes.html
PS C:\>Get-Process | ConvertTo-Html name,path,fileversion | Set-Content c:\processes.htm
Save the system services to C:\services.html
PS C:\>get-service | ConvertTo-Html -Title "Services" -Body "<H2>The result of get-service</H2> " -Property Name,Status > c:\services.html
Save the system services to C:\services.html and format in color:
PS C:\>get-service | ConvertTo-Html -Title "Services" -Body "<H2>The result of get-service</H2> " -Property Name,Status |
foreach {if($_ -like "*<td>Running</td>*"){$_ -replace "<tr>", "<tr bgcolor=green>"}elseif($_ -like "*<td>Stopped</td>*"){$_ -replace "<tr>", "<tr bgcolor=red>"}else{$_}} > c:\services.html
Service examples from Hung Yuwu
"If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack" - Winston Churchill
Related Powershell Commands:
export-clixml - Produce a clixml representation of a powershell objects
export-csv - Export to Comma Separated Values (spreadsheet)