Get Cmdlet Help URL

I was toying around with PowerShell help this morning and as usually happens one thing leads to another. When you run Get-Help, or use the wrapper function Help, you are actually getting an object: MamlCommandHelpInfo. This object has properties that you are use to seeing like name and synopsis.


PS C:\> get-help get-service | Select Name,Syntax,RelatedLinks

Name syntax relatedLinks
---- ------ ------------
Get-Service @{syntaxItem=System.Man... @{navigationLink=Syste...

As you can see, some of these properties are nested objects.


PS C:\> get-help get-service | Select RelatedLinks | get-member

TypeName: Selected.System.Management.Automation.PSCustomObject

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
relatedLinks NoteProperty MamlCommandHelpInfo#relatedLinks relatedLinks=@{na...

I wanted to try something with related links, specifically those links which PowerShell uses for online help.


PS C:\> get-help get-service | Select -expandproperty RelatedLinks

Online version: http://go.microsoft.com/fwlink/?LinkID=113332
Start-Service
Stop-Service
Restart-Service
Resume-Service
Suspend-Service
Set-Service
New-Service

It is easy to forget, that these are still objects.


PS C:\> get-help get-service | Select -expandproperty RelatedLinks | get-member

TypeName: MamlCommandHelpInfo#relatedLinks

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
navigationLink NoteProperty System.Management.Automation.PSObject[] navigati...

I see that these related link objects have a NavigationLink property so I’ll expand it:


PS C:\> get-help get-service | Select -expandproperty RelatedLinks | select -e
xpand navigationlink

linkText uri
-------- ---
Online version: http://go.microsoft.com/fwlink/?Link...
Start-Service
Stop-Service
Restart-Service
Resume-Service
Suspend-Service
Set-Service
New-Service

Now we’re getting somewhere. All I want is the link with a URI value.


PS C:\> get-help get-service | Select -expandproperty RelatedLinks | select -expandproperty navigationlink | where {$_.uri}

linkText uri
-------- ---
Online version: http://go.microsoft.com/fwlink/?Link...

Very cool. Now that I have the basic concept down for a single cmdlet, I can modify my expression to pull this value out of the nested objects and bring it “up”.


Get-Help get-service |
Select Name,Synopsis,@{Name="URI";Expression={
($_.RelatedLinks | select -ExpandProperty NavigationLink | where {$_.uri}).uri}} |
Where {$_.URI}

I’m using a hash table to define a custom property called URI that pulls the URI property, if found “up”. When I run this code and pipe it to Format-List to make it easier to read I get a result like this:


Name : Get-Service
Synopsis : Gets the services on a local or remote computer.
URI : http://go.microsoft.com/fwlink/?LinkID=113332

Beautiful. All I need to do now is modify my code to work with more cmdlets.


Get-Command -CommandType cmdlet | Get-Help | Select Name,Synopsis,@{Name="URI";Expression={
($_.RelatedLinks | select -ExpandProperty NavigationLink | where {$_.uri}).uri}} | Where {$_.URI}

This one line command will get all cmdlets in my current PowerShell session and display the cmdlet name, synopsis and help URL if found. The PowerCLI cmdlets include online help, but not all of them so when I run this command in a session with them loaded I’ll only get those cmdlets with an online help link.

What I really wanted to show here is discovering an object’s details, especially if there are nested object properties. PowerShell is all about objects in the pipeline and once you get a hold of that concept you can do some amazing things with very little effort. I’ll be back tomorrow to take this one more step.