简体   繁体   中英

Support Get-Help for custom PowerShell cmdlet

I have created some custom PowerShell Cmdlets in C# and would like to provide some information to be displayed using the get-help cmdlet; eg "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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM