Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Explain HTML formatting in PowerShell?
HTML is another form of output in PowerShell. It is the rich form of output and you can use various CSS styles to make the output more interactive. We will use the Convertto-HTML cmdlet to convert the output in the HTML format.
Here is the Syntax of the Convertto-HTML cmdlet.
Example
ConvertTo-Html [-InputObject] [[-Property]
Let's take one simple example of Convertto-HTML with InputObject parameter.
ConvertTo-Html -InputObject (Get-Date)
The output will be on the same console.
PS C:\WINDOWS\system32> ConvertTo-Html -InputObject (Get-Date)HTML TABLE
| DisplayHint | DateTime | Date | Day | DayOfWeek | DayOfYear | Hour | Kind | Millisecond | MinuteMonth | Second | Ticks | TimeOfDay | Year | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DateTime | 17 June 2020 08:33:06 | 17-06-2020 00:00:00 | 17 | Wednesday | 169 | 8 | Local | 8 29 | 33 | 6 | 6 | 637279795868299280 | 08:33:06.8299280 | 2020 |
So, you need to redirect the output in the .html extension.
ConvertTo-Html -InputObject (Get-Date) > C:\temp\dateoutput.html
Output

Here, You can also use the Pipeline as the Input Object. An example is shown below.
Below we will convert Get-Service output to HTML format.
Get-Service | Select Name, Status, StartType | ConvertTo-Html | Out-File Servicesoutput.html
When you check the output in a file called ServicesOutput.html, HTML file will be as below.
Output

You can also check the content of the HTML by right click and edit with Notepad, Notepad++ or any compatible editor.
The HTML file will be as below in the editor. You can see that the title “HTML Table”, it is added automatically. You can change the title in the editor but it won’t help as it will be overwritten to default every time you run the script.
HTML TABLE
| Name | Status | StartType |
|---|---|---|
| AarSvc_69f5c | Stopped | Manual |
| AdobeARMservice | Running | Automatic |
| AdobeFlashPlayerUpdateSvc | Stopped | Manual |
| AJRouter | Stopped | Manual |
| ALG | Stopped | Manual |
| AppIDSvc | Stopped | Manual |
| Appinfo | Running | Manual|
| AppMgmt | Stopped | Manual |
| AppReadiness | Stopped | Manual |
| AppVClient | Stopped | Disabled |




