PowerShell Logo Small

ConvertTo-Html



This is the built-in help made by Microsoft for the command 'ConvertTo-Html', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser.

SYNTAX


ConvertTo-Html [[-Property] [<Object[]>]] [[-Head] [<String[]>]] [[-Title] [<String>]] [[-Body] [<String[]>]] [-As {Table | List}] [-CssUri [<Uri>]] [-InformationAction
{SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-InputObject [<PSObject>]] [-PostContent [<String[]>]]
[-PreContent [<String[]>]] [<CommonParameters>]
ConvertTo-Html [[-Property] [<Object[]>]] [-As {Table | List}] [-Fragment] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.String>]] [-InputObject [<PSObject>]] [-PostContent [<String[]>]] [-PreContent [<String[]>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can use this cmdlet to display the output of a command in a
Web page.


You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the
object, and to return only the table or list fragment, instead of a strict DTD page.


When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the
remaining objects do not have one of the specified properties, the property value of that object is an empty cell. If the remaining objects have additional properties, those
property values are not included in the file.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293950
ConvertTo-Csv
ConvertTo-Xml

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>convertto-html -inputobject (get-date)



This command creates an HTML page that displays the properties of the current date. It uses the InputObject parameter to submit the results of a Get-Date command to the
ConvertTo-Html cmdlet.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>get-alias | convertto-html > aliases.htm
PS C:\>invoke-item aliases.htm



This command creates an HTML page that lists the Windows PowerShell aliases in the current console.

The command uses the Get-Alias cmdlet to get the aliases. It uses the pipeline operator (|) to send the aliases to the ConvertTo-Html cmdlet, which creates the HTML page.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>get-eventlog -logname "Windows PowerShell" | convertto-html > pslog.htm



This command creates an HTML page called pslog.htm that displays the events in the Windows PowerShell event log on the local computer.

It uses the Get-EventLog cmdlet to get the events in the Windows PowerShell log and then uses the pipeline operator (|) to send the events to the ConvertTo-Html cmdlet.

The command also uses the redirection operator (>) to send the HTML code to the pslog.htm file.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>get-process | convertto-html -property Name, Path, Company -title "Process Information" > proc.htm; ii proc.htm



These commands create and open an HTML page that lists the name, path, and company of the processes on the local computer.

The first command uses the Get-Process cmdlet to get objects that represent the processes running on the computer. The command uses the pipeline operator (|) to send the
process objects to the ConvertTo-Html cmdlet.

The command uses the Property parameter to select three properties of the process objects to be included in the table. The command uses the Title parameter to specify a
title for the HTML page. The command also uses the redirection operator (>) to send the resulting HTML to a file named Proc.htm.

The second command uses the Invoke-Item cmdlet (alias = ii) to open the Proc.htm in the default browser. The two commands are separated by a semicolon (;).










-------------------------- EXAMPLE 5 --------------------------

PS C:\>get-service | convertto-html -CssUri "test.css"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>HTML TABLE</title>
<link rel="stylesheet" type="text/css" href="test.css" />
...



This command creates an HTML page of the service objects that the Get-Service cmdlet returns. The command uses the CssUri parameter to specify a cascading style sheet for
the HTML page.

The CssUri parameter adds an additional "<link rel="stylesheet" type="text/css" tag to the resulting HTML. The HREF attribute in the tag contains the name of the style sheet.










-------------------------- EXAMPLE 6 --------------------------

PS C:\>get-service | convertto-html -as LIST > services.htm



This command creates an HTML page of the service objects that the Get-Service cmdlet returns. The command uses the As parameter to specify a list format. The redirection
operator (>) sends the resulting HTML to the Services.htm file.










-------------------------- EXAMPLE 7 --------------------------

PS C:\>get-date | cth -fragment
<table>
<colgroup>...</colgroup>
<tr><th>DisplayHint</th><th>DateTime</th><th>Date</th><th>Day</th><th>DayOfWeek</th><th>DayOfYear</th><th>Hour</th>
<th>Kind</th><th>Millisecond</th><th>Minute</th><th>Month</th><th>Second</th><th>Ticks</th><th>TimeOfDay</th><th>Year</th></tr>
<tr><td>DateTime</td><td>Monday, May 05, 2008 10:40:04 AM</td><td>5/5/2008 12:00:00 AM</td><td>5</td><td>Monday</td>
<td>126</td><td>10</td><td>Local</td><td>123</td><td>40</td><td>5</td><td>4</td><td>633455808041237213</td><td>10:40:04.12
37213</td><td>2008</td></tr>
</table>



This command uses ConvertTo-Html to generate an HTML table of the current date. The command uses the Get-Date cmdlet to get the current date. It uses a pipeline operator (|)
to send the results to the ConvertTo-Html cmdlet (aliased as "cth").

The ConvertTo-Html command includes the Fragment parameter, which limits the output to an HTML table. As a result, the other elements of an HTML page, such as the <HEAD> and
<BODY> tags, are omitted.










-------------------------- EXAMPLE 8 --------------------------

PS C:\>get-eventlog -log "Windows PowerShell" | convertto-html -property id, level, task



This command uses the Get-EventLog cmdlet to get events from the "Windows PowerShell" event log.

It uses a pipeline operator (|) to send the events to the ConvertTo-Html cmdlet, which converts the events to HTML format.

The ConvertTo-Html command uses the Property parameter to select only the ID, Level, and Task properties of the event.










-------------------------- EXAMPLE 9 --------------------------

PS C:\>get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre
"<P>Generated by Corporate IT</P>" -post "For details, contact Corporate IT." > services.htm; ii services.htm



This command creates and opens a Web page that displays the services on the computer that begin with "A". It uses the Title, Body, PreContent, and PostContent parameters of
ConvertTo-Html to customize the output.

The first part of the command uses the Get-Service cmdlet to get the services on the computer that begin with "A". The command uses a pipeline operator (|) to send the
results to the ConvertTo-Html cmdlet. The command uses a redirection operator (>) to send the output to the Services.htm file.

A semicolon (;) ends the first command and starts a second command, which uses the Invoke-Item cmdlet (alias = "ii") to open the Services.htm file in the default browser.