Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dynamic Parameters for Roles #10

Closed
mapresto opened this issue Feb 6, 2019 · 1 comment
Closed

Use Dynamic Parameters for Roles #10

mapresto opened this issue Feb 6, 2019 · 1 comment
Assignees
Projects
Milestone

Comments

@mapresto
Copy link
Owner

mapresto commented Feb 6, 2019

Is your feature request related to a problem? Please describe.
There are multiple functions that reuses the same validateset for parameters. A dynamic parameter can allow for a single source of updating for this.

Describe the solution you'd like
Something close to below:

DynamicParam {
                # Set the dynamic parameters' name
                $ParameterName = "Role"

                # 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 = $true

                # Add the attributes to the attributes collection
                $AttributeCollection.Add($ParameterAttribute)

                # Generate and set the ValidateSet 
                $roleSet = Import-CSV C:\Users\mapresto\desktop\DynamicParamTest\Roles.csv -Header Role | Select -ExpandProperty Role
                $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($roleSet)

                # 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
        {
            $Role = $PSBoundParameters[$ParameterName]
        }

        Process {}
@mapresto mapresto added this to the 1.1.0.0 milestone Feb 6, 2019
@mapresto mapresto self-assigned this Feb 6, 2019
@mapresto mapresto added this to To do in 2.0.0.0 Feb 7, 2019
@mapresto mapresto moved this from To do to In progress in 2.0.0.0 Feb 7, 2019
@mapresto
Copy link
Owner Author

Roles have been largely standardized in 2.0. For public functions, roles.csv is filling a dynamic parameter for the function.

@mapresto mapresto moved this from In progress to Done in 2.0.0.0 May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
2.0.0.0
  
Done
Development

No branches or pull requests

1 participant