开发者

Support Get-Help for custom PowerShell cmdlet

开发者 https://www.devze.com 2022-12-20 13:05 出处:网络
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 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 开发者_StackOverflow中文版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.

0

精彩评论

暂无评论...
验证码 换一张
取 消