This tutorial will guide the users to convert the output to an HTML web page.
How to Use ConvertTo-Html (Microsoft.PowerShell.Utility) Cmdlet in PowerShell?
To convert an object or output of a command into an HTML page. First, place any cmdlet and then pipe it to the “ConvertTo-Html” cmdlet using the pipe operator “|”. Doing so will output a large string in the PowerShell console.
Let’s explore some of the examples to know further about the stated cmdlet.
Example 1: Use the “ConvertTo-Html” Cmdlet to Convert an Object’s Output into an HTML Page
To convert an object’s or cmdlet’s output to an HTML web page, first, place the cmdlet. Then, pipe it to the “ConvertTo-Html” cmdlet using the pipe “|” operator:
Example 2: Convert a Commands Output into an HTML Page and Save it into a Specified File
To send output to a text file, pipe the command to the “Out-File” cmdlet. Then, use the “-FilePath” operator and assign it the target file path:
Execute the following command to check if the output was saved into a file or not:
Example 3: Create a Web Page Displaying the Services on it
First, mention the “ConvertTo-Html” cmdlet. Then, use the “-InputObject” parameter and assign it the cmdlet that needs to be converted into HTML enclosed within parentheses:
That’s it! You have learned the usage of the “ConvertTo-Html” cmdlet in PowerShell.
Conclusion
The “ConvertTo-Html” cmdlet is used to convert the PowerShell console’s output into an HTML web page. For this specified purpose, specify the cmdlet and then pipe it to the “ConvertTo-Html” cmdlet. This post has elaborated on PowerShell’s “ConvertTo-HTML” with the help of various examples.