As I hope you know, PowerShell cmdlets can include links to online help. This is very handy because it is much easier to keep online help up to date. To see online help for a cmdlet use the -online parameter.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
get-help get-wmiobject -online
I decided to take things to another level and create an HTML page with links to online help
I created a relatively simple script called New-OnlineHelpPage.ps1. The script uses Get-Command to retrieve a cmdlet name, it's module or snapin and it's help link.
$data=Get-Command -CommandType Cmdlet | Where {$_.HelpURI} |Sort-object -property $Sort | Select Name,ModuleName,@{Name="Online Help";Expression={$_.HelpURI}}
This expression filters out cmdlets without an online link. By default the script sorts by cmdlet name but if you use the -SortModule parameter, it will sort by module or snapin. Get-Command treats them as the same. The data is piped to ConvertTo-HTML to create the HTML report.
$data | ConvertTo-Html -Title "Online Command Help" -CssUri $CSS -PreContent "<H2>PowerShell Online Cmdlet Help from $env:computername </H2>"
The function lets you specify a CSS file path which is stored in $CSS and I include a sample one in the download below. But now for the fun part. The help url looks like a link but it isn't actionable. Remember that ConvertTo-HTML doesn't create a file, it creates HTML which means I can intercept it and use a regular expression to find the URL and replace it with HTML code that turns it into a link. At the end of the process I finally pipe the HTML to Out-File to create the report.
ForEach { #use a regex to find the url [regex]$urlRegEx="(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?" [regex]$tdRegEx="<td>$($urlRegex.ToString())</td>" #only get urls in the table if ($_ -match $tdRegEx) { #replace the link text with an html link $_ -match $urlRegEx | Out-Null #open each link in a new tab $link="<a href=$($matches[0]) target='_blank'>$($matches[0])</a>" $_.Replace($($matches[0]),$link) } else { #pass the line on write $_ } } | out-file -FilePath $file
The last step is to launch the HTML page using Invoke-Item. This will launch the file with whatever application is associated with the file extension you specified.
#view the file Write-Verbose "Launching $file" Invoke-item -Path $file
The script takes a few parameters.
Param( [Parameter(Position=0)] [ValidateNotNullorEmpty()] [string]$file="$env:temp\PSOnlineHelp.html", [string]$CSS="c:\scripts\sample.css", [switch]$SortModule )
The file it creates is stored in you TEMP folder by default. The script will process any cmdlet loaded in your PowerShell session so you can add snapins like PowerCLI or modules like ActiveDirectory and get those links as well. What you end up with is a single page with links to all the online help.
Even if this isn't of use, I hope you picked up a little knowledge about Get-Command and ConvertTo-HTML. You can download a zip file with my script and a sample CSS file here.