Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands. One interesting property returned by this cmdlet is the link to online (TechNet) source which provides detailed documentation of the cmdlet. Wouldn’t it be nice if we have all the links from each cmdlet captured in to a simple HTML table? Here is a sample built on my system.
This way, we can just click on the link related to any cmdlet and reach the online documentation easily. Let us see how we can achieve this.
Get-Command | ConvertTo-Html Name, ResolvedCommand, helpuri, CommandType | Out-File C:\dell\testhelp.html
ConvertTo-HTML can be used generate HTML content. However, this is not so well formatted. As you see here, there are no table borders and the HelpURI is not a clickable link.

Let us quickly see how we can modify this further.
Get-Command | % { $_ | Add-Member -name Url -memberType NoteProperty -value “<a target=_blank href=`”$( $_.helpuri )`”>$( $_.helpuri )</a>” }
$htmlContent = $commands | Sort-Object -Property CommandType | ConvertTo-Html Name, ResolvedCommand, Url, CommandType -head $a
[System.Web.HttpUtility]::HtmlDecode($htmlContent) | Out-File C:\scripts\help.html
We use Add-Member cmdlet to add a custom property to to the Get-Command instance and we use this method to add the HTML <a> tags. However, since this is a string, HTML source will not be decoded to show a hyperlink. So, we need to use HTMLDecode() function to display the links.

Okay, this is a bit better. Let us now add some style to this and create a better table layout. ConvertTo-HTML supports -Head, -PreContent and -PostContent to add custom HTML code to cmdlet’s output. The following code defines the HTML style for our table.
$style = “<style>”
$style = $style + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$style = $style + “TH{color: white; border-width: 1px;border-style: solid;border-color: white;background-color: black;}”
$style = $style + “TD{border-width: 1px;border-style: solid;border-color: black;}”
$style = $style + “</style>”
Here is the updated code for generating the formatted HTML output.
Get-Command | % { $_ | Add-Member -name Url -memberType NoteProperty -value “<a target=_blank href=`”$( $_.helpuri )`”>$( $_.helpuri )</a>” }
$htmlContent = $commands | Sort-Object -Property CommandType | ConvertTo-Html Name, ResolvedCommand, Url, CommandType -title “PowerShell Help Quick Reference” -head $style
[System.Web.HttpUtility]::HtmlDecode($htmlContent) | Out-File C:\scripts\help.html

Finally, as usual, let us put it in to a simple function
Function Generate-HtmlHelp {
$style = “<style>”
$style = $style + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$style = $style + “TH{color: white; border-width: 1px;border-style: solid;border-color: white;background-color: black;}”
$style = $style + “TD{border-width: 1px;border-style: solid;border-color: black;}”
$style = $style + “</style>”Get-Command | % { $_ | Add-Member -name Url -memberType NoteProperty -value “<a target=_blank href=`”$( $_.helpuri )`”>$( $_.helpuri )</a>” }
$htmlContent = $commands | Sort-Object -Property CommandType | ConvertTo-Html Name, ResolvedCommand, Url, CommandType -title “PowerShell Help Quick Reference” -head $style
[System.Web.HttpUtility]::HtmlDecode($htmlContent) | Out-File C:\scripts\help.html
}
You can also download the script here.
(Downloaded 69 times)

{ 1 trackback }