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.
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.
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: This example employs the tiny backtick
(`) to word-wrap the instruction to Out-File.
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your PowerShell scripts. Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory or Exchange Server.
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: Get-Process | Get-Member.
Note 6: Observe how the -head parameter
controls the formatting via the $a variable.
Guy Recommends: Solarwinds' Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the
users with their fields in the
top row, and save as .csv file. Then launch this FREE utility and match
your fields with AD's
attributes, click to import the users. Optionally, you can
provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
# Research ConvertTo-Html Parameters Clear-Host Get-Help
ConvertTo-Html -full
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 Clear-Host Get-Command
-verb ConvertTo
Other useful cmdlets in this family include ConvertTo-Csv.
»
Summary of PowerShell's ConvertTo-Html
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
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.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.