views:

173

answers:

2

I have created some custom PowerShell Cmdlets in C# and would like to provide some information to be displayed using the get-help cmdlet; e.g. "get-help my-cmdlet".

I have created a basic snapin deriving from PSSnapIn and overridden the Description, Name and Vendor properties. I have also created my help file "Cmdlets.dll-Help.xml". Cmdlets.dll is the correct name of the assembly as instructed here.

I created the following script to quickly test this help out:

$ErrorActionPreference = "Stop"
$scriptFolder = Split-Path $script:MyInvocation.MyCommand.Path

$dll = ($scriptFolder + "\Release\x64\Cmdlets.dll")
Write-Host "Testing Cmdlets in $dll" -fore Green

[System.Reflection.Assembly] $assembly = [System.Reflection.Assembly]::LoadFrom($dll)
Import-Module -assembly $assembly

get-help get-latestfiles

This seems to just turn up some default help about the cmdlet parameters but fails to get any of my examples I have written in the XML file. Does anyone have any thoughts on why this is?

+1  A: 

Get-Help only shows a subset of the help for a cmdlet by default. Specify -Full to see parameter help and your examples:

Get-Help Get-LatestFiles -Full

If that isn't the issue (sounds like it isn't) then have a look at this PowerShell script that generates skeleton MAML files. Run it and use its output to see if you get proper help displayed.

Keith Hill
Unfortunately it would seem like I'm missing something else. Specifying the full switch just displays the same default help that Powershell 2 provides.
Jason
+1  A: 

Seems like there were two issues for my help not working. First was that the XML needs to be copied to the output directory of the Cmdlet DLL in order for Powershell to be picked up.

Second reason seems to have been an error in my help file. I'm not sure what this was but Powershell just seemed to fail silently even though the error action preference was set to stop. I ended up lifting XML straight out of C:\Windows\System32\WindowsPowerShell\v1.0\en-US\Microsoft.PowerShell.Commands.Management.dll-Help.xml and modifying it to suit my needs.

Jason