I have a user module I'm writing, that I'm trying to document with inline/comment-based help.
A function in the module:
<#
.Synopsis
Get-CBSNoun returns information about the nouns in the CBS system. You use Get-CBSNoun
to get a list of the available items that you can invoke operations on in the system.
.DESCRIPTION
If you don't specify a noun, this function returns all the nouns in the system. If you
specify a noun, it returns all of those nouns available in the system. The method of
construction for this function was based on the Get-Help cmmdlet, so no params returns
all the nouns and a specific one returns information about that one.
.PARAMETER Noun
Optional. The noun you want information about.
.EXAMPLE
Get-CBSNoun
.EXAMPLE
Get-CBSNoun -Noun Product
#>
function Get-CBSNoun
{
[CmdletBinding()]
[OutputType([string])]
Param
($dummyparam)
DynamicParam {
$ParameterName = 'Noun'
# Create the dictionary
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
# Create the collection of attributes
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
# Create and set the parameters' attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $false
$ParameterAttribute.Position = 1
$ParameterAttribute.ParameterSetName = "__AllParameterSets"
# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)
# Generate and set the ValidateSet
$arrSet = (Get-Item $PSScriptRoot\*.csv).BaseName
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary
}
Begin
{
$noun = $PsBoundParameters[$ParameterName]
Write-Verbose $PSScriptRoot
}
Process
{
if ($noun)
{
switch ($noun)
{
Default
{
Write-Verbose "Noun to search is: $noun"
$pathToSearch = "$PSScriptRoot\$noun.csv"
Write-Verbose "Generated path to search is: $pathToSearch"
if (Test-Path $pathToSearch)
{
Write-Verbose "Test-path for $pathtoSearch passed"
import-csv $pathToSearch
}
else
{
$errorMessage = "No noun: $Noun found"
throw $errorMessage
}
}
}
}
else
{
(Get-Item $PSScriptRoot\*.csv).BaseName | select @{Name='Noun';Expression={$_}}
}
}
End
{
}
}
But when I run:
> get-help Get-CBSNoun -full
I don't see any information about the 'Noun' parameter. $DummyParam is there. But Noun is missing.
Further, get-help appears completely ignorant of the dynamic parameter:
PS Function:\> get-help get-cbsnoun -parameter noun
get-help : No parameter matches criteria noun.
At line:1 char:1
+ get-help get-cbsnoun -parameter noun
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.Manageme...CommandHelpInfo:ProviderCommandHelpInfo) [Get-Help], PSArgumentException
+ FullyQualifiedErrorId : NoParmsFound,Microsoft.PowerShell.Commands.GetHelpCommand
What do I need to do to either:
a) the comment based help
b) the dynamic parameter creation
c) other parameters passed to get-help
to make this work as I'm expecting?
Thanks kindly!