If I have a function with dynamic parameters, how can I add help based on comments so that when executed by the user, Get-Helpit will still show dynamic parameters?
for example Here is my function without any help based on comments.
function Test-DynamicParam{
[CmdletBinding(PositionalBinding=$false)]
param(
[Parameter(Mandatory=$false)][string]$NamedStaticParam1,
[Parameter(Mandatory=$false)][string]$NamedStaticParam2
)
dynamicparam {
$paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
$paramname = "NamedDynamicParam1"
$values = 'foo','bar'
$attributes = new-object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = "__AllParameterSets"
$attributes.Mandatory = $true
$attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributeCollection.Add($attributes)
$ValidateSet = new-object System.Management.Automation.ValidateSetAttribute($values)
$attributeCollection.Add($ValidateSet)
$dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter($paramname, [string], $attributeCollection)
$paramDictionary.Add($paramname, $dynParam)
return $paramDictionary
}
process{
$PSBoundParameters.NamedDynamicParam1
$PSBoundParameters.NamedStaticParam1
$PSBoundParameters.NamedStaticParam2
}
}
If I ran Get-Help Test-DynamicParam -Full, he gave me
NAME
Test-DynamicParam
SYNTAX
Test-DynamicParam -NamedDynamicParam1 {foo | bar} [-NamedStaticParam1 <string>] [-NamedStaticParam2 <string>] [<CommonParameters>]
PARAMETERS
-NamedDynamicParam1 <string>
Required? true
Position? Named
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? true
-NamedStaticParam1 <string>
Required? false
Position? Named
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-NamedStaticParam2 <string>
Required? false
Position? Named
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
None
OUTPUTS
System.Object
ALIASES
None
REMARKS
None
but if I add help based on comments, for example:
function Test-DynamicParam{
<
.SYNOPSIS
A test for the dynamic parameter list populating
.DESCRIPTION
Using this for Stack Overflow
.NOTES
Adding comment-based help breaks the parameter and syntax help
...
The launch Get-Help Test-DynamicParam -Fullshows only static parameters in the SYNTAX section and the PARAMETERS section :
NAME
Test-DynamicParam
SYNOPSIS
A test for the dynamic parameter list populating
SYNTAX
Test-DynamicParam [-NamedStaticParam1 <String>] [-NamedStaticParam2 <String>] [<CommonParameters>]
DESCRIPTION
Using this for Stack Overflow
PARAMETERS
-NamedStaticParam1 <String>
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NamedStaticParam2 <String>
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http:
INPUTS
OUTPUTS
NOTES
Adding comment-based help breaks the parameter and syntax help
RELATED LINKS
.PARAMETER NamedDynamicParam1 , , . , , Get-Help. , , ,