PowerShell ConvertTo-Html Cmdlet
When testing PowerShell's ConvertTo-Html cmdlet, the best way of making sense of the output is if you employ Invoke-Item to view the resulting web page.
Topics for PowerShell's ConvertTo-Html
Introduction to ConvertTo-Html
ConvertTo-Html feeds on input from another PowerShell cmdlet; the output is displayed in a web page. Your alternatives are to save the data in a text file, in which case you would employ Out-File, do nothing and display the data in the PowerShell ISE, or call for ConvertTo-Html.
The purpose of this script is to simply list PowerShell's aliases in a web page.
# PowerShell ConvertTo-Html Example
Note 1: I decided to restrict the output columns to just the alias's name and its definition.
Note 2: ConvertTo-Html needs a file name; I used Out-File, but you could use the greater than arrow > to redirect the results.
Note 3: As I really wanted to view a table of cmdlets with their corresponding alias, I called for Invoke-Item to open the .htm file.
Note 4: There is no need to employ the backtick (`) to word-wrap the instruction to Out-File; if you place a pipe (|) at the very end of the line PowerShell realises that the command continues on the next line.
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
The key to this example is tracing the processes, see how
ConvertTo-Html filters just then name and handles. If you want to research
other properties then run this command:
# PowerShell ConvertTo-Html Cmdlet
Note 5: In this ConvertTo-Html example the -property parameter is assumed.
The purpose of this example is to use html formatting to produce grid lines and even a background color.
Note 6: Observe how the -head parameter controls the formatting via the $a variable.
This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer's Toolset now!
# Research ConvertTo-Html Parameters
Note 7: PowerShell's own Get-Help cmdlet reveals useful switches or parameters, for instance you can modify ConvertTo-Html's default table view with the parameter -as List. While most of the parameters are cosmetic, the -properties performs a useful filtering function.
More Members of the ConvertTo Family
# Research More ConvertTo Verbs
Other useful cmdlets in this family include ConvertFrom-Csv.
Summary of PowerShell's ConvertTo-Html Cmdlet
Once you have tried ConvertTo-Html you will see if this cmdlet is just what you need, or if Out-File or Out-Grid would be better. In my opinion if you choose ConvertTo-Html then mostly you will need to append the Invoke-Item parameter to display the actual web page.
If you like this page then please share it with your friends
See more Microsoft PowerShell output tutorials:
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.