Skip to content

Dynamic Parameters are too Difficult to Construct #20395

@StartAutomating

Description

@StartAutomating

Summary of the new feature / enhancement

As a heavy user of dynamic parameters, I often find myself tripping over their basic failures in constructability.

Dynamic Parameters are needlessly difficult to construct.

The shortest possible constructor is:

[Management.Automation.RuntimeDefinedParameter]::new("A", [psobject], @())

and it fails in an entreatingly confusing way, informing me that I could not bind "A" to "AllParameterSets", without telling me why.

Dynamic Parameters should be easier to construct.

The need goes beyond simplifying existing implementation and fixing its buggier parts:

A very common scenario is exposing dynamic parameters from one command to another.

This should also be easier to construct

Proposed technical implementation details (optional)

  • Add simplified constructors to [Management.Automation.RuntimeDefinedParameter]
    • Constructing from only a name should create a [PSObject] parameter that accepts ValueFromPipelineByPropertyName
    • Constructing from a name and a type should add an empty [Parameter()] attribute
  • Allow [Management.Automation.RuntimeDefinedParameter] to be coerced from [Management.Automation.ParameterMetadata]
  • Create extension methods to assist in custom conversion to [Management.Automation.RuntimeDefinedParameter]
  • Enable adding dictionaries to [Management.Automation.RuntimeDefinedParameterDictionary]
  • Adding type accelerators [DynamicParameter], [DynamicParameters], so that less typing is required to create them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions