Skip to content

New-DynamicParam

SYNOPSIS

Creates a new dynamic parameter for a function.

SYNTAX

New-DynamicParam [-Name] <String> [[-Alias] <String[]>] [[-Type] <Type>] [[-ParameterSetName] <String>]
 [-Mandatory] [[-Position] <Int32>] [-ValueFromPipeline] [-ValueFromPipelineByPropertyName]
 [-ValueFromRemainingArguments] [[-HelpMessage] <String>] [[-Comment] <String>]
 [[-ValidateScript] <ScriptBlock>] [[-ValidatePattern] <Regex>] [[-ValidatePatternOptions] <RegexOptions[]>]
 [[-ValidateCount] <Int32[]>] [[-ValidateRange] <Object>] [[-ValidateSet] <Object>]
 [[-ValidateLength] <Int32[]>] [-ValidateNotNullOrEmpty] [[-ValidationErrorMessage] <String>]
 [-SupportsWildcards] [-AllowEmptyString] [-AllowNull] [-AllowEmptyCollection]
 [[-DynamicParamDictionary] <RuntimeDefinedParameterDictionary>] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

Creates a new dynamic parameter for a function.

EXAMPLES

EXAMPLE 1

dynamicparam {
    $DynamicParamDictionary = New-DynamicParamDictionary
    $dynParam = @{
        Name                   = 'GitignoreTemplate'
        Alias                  = 'gitignore_template'
        Type                   = [string]
        ValidateSet            = Get-GitHubGitignoreList
        DynamicParamDictionary = $DynamicParamDictionary
    }
    New-DynamicParam @dynParam
    $dynParam2 = @{
        Name                   = 'LicenseTemplate'
        Alias                  = 'license_template'
        Type                   = [string]
        ValidateSet            = Get-GitHubLicenseList | Select-Object -ExpandProperty key
        DynamicParamDictionary = $DynamicParamDictionary
    }
    New-DynamicParam @dynParam2
    return $DynamicParamDictionary
}

PARAMETERS

-Name

Specifies the name of the parameter.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Alias

Specifies the aliases of the parameter.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Type

Specifies the data type of the parameter.

Type: Type
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ParameterSetName

Specifies the parameter set name.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: __AllParameterSets
Accept pipeline input: False
Accept wildcard characters: False

-Mandatory

Specifies if the parameter is mandatory. Parameter Set specific

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Position

Specifies the parameters positional binding. Parameter Set specific

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-ValueFromPipeline

Specifies if the parameter accepts values from the pipeline. Parameter Set specific

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ValueFromPipelineByPropertyName

Specifies if the parameter accepts values from the pipeline by property name. Parameter Set specific

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ValueFromRemainingArguments

Specifies if the parameter accepts values from the remaining command-line arguments that are not associated with another parameter. Parameter Set specific

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-HelpMessage

Specifies the help message of the parameter. Parameter Set specific

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Comment

Specifies the comments of the parameter.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateScript

Specifies the validate script of the parameter.

Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: False
Position: 8
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidatePattern

Specifies the validate regular expression pattern of the parameter.

Type: Regex
Parameter Sets: (All)
Aliases:

Required: False
Position: 9
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidatePatternOptions

Specifies the validate regular expression pattern options of the parameter. For more info see RegexOptions.

Type: RegexOptions[]
Parameter Sets: (All)
Aliases:
Accepted values: None, IgnoreCase, Multiline, ExplicitCapture, Compiled, Singleline, IgnorePatternWhitespace, RightToLeft, ECMAScript, CultureInvariant, NonBacktracking

Required: False
Position: 10
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateCount

Specifies the validate number of items for the parameter.

Type: Int32[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 11
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateRange

Specifies the validate range of the parameter.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: 12
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateSet

Specifies the validate set of the parameter.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: 13
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateLength

Specifies the validate length of the parameter.

Type: Int32[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 14
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ValidateNotNullOrEmpty

Specifies if the parameter accepts null or empty values.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ValidationErrorMessage

The custom error message pattern that is displayed to the user if validation fails. This parameter is not supported on Windows PowerShell Desktop Edition, if specified it will be ignored.

Examples of how to use this parameter: - ValidatePattern -> "The text '{0}' did not pass validation of the regular expression '{1}'". {0} is the value, {1} is the pattern. - ValidateSet -> "The item '{0}' is not part of the set '{1}'. {0} is the value, {1} is the set. - ValidateScript -> "The item '{0}' did not pass validation of script '{1}'". {0} is the value, {1} is the script.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 15
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-SupportsWildcards

Specifies if the parameter accepts wildcards.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-AllowEmptyString

Specifies if the parameter accepts empty strings.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-AllowNull

Specifies if the parameter accepts null values.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-AllowEmptyCollection

Specifies if the parameter accepts empty collections.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-DynamicParamDictionary

Specifies the dynamic parameter dictionary.

Type: RuntimeDefinedParameterDictionary
Parameter Sets: (All)
Aliases:

Required: False
Position: 16
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Void

NOTES

https://psmodule.io/DynamicParams/Functions/New-DynamicParam/