Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 1.0 » ConvertTo-Html

ConvertTo-Html - Powershell 1.0 CmdLet

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.

ConvertTo-Html

Description
Convert the input into an HTML table

Usage


Options
-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

Example(s)
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