Giter Site home page Giter Site logo

Comments (4)

oze4 avatar oze4 commented on July 21, 2024

@lazywinadmin - this should be resolved now. I have included a fix as part of my recent PR.

Let me know if you need anything!

from adsips.

lazywinadmin avatar lazywinadmin commented on July 21, 2024

Thanks @oze4

from adsips.

lazywinadmin avatar lazywinadmin commented on July 21, 2024

Unsure we should go forward with Position=0 approach in the future, Instead maybe re-arrange params ?

from adsips.

oze4 avatar oze4 commented on July 21, 2024

Unsure we should go forward with Position=0 approach in the future, Instead maybe re-arrange params ?

When using ParameterSetName attributes you have to specify Position = x if you want to use "nameless" parameters (meaning, only supplying a value.. ex: Some-Func -Name 'Gary' versus nameless: Some-Func 'Gary' ..

It is worth digging into more, to see if it is possible to force PowerShell to respect order without having to specify Position, when using ParameterSetName..

I wrote the following functions to highlight the root issue (at a high level):

function Test-ParamOrder_One {
    param(
        [Parameter(Mandatory, ParameterSetName="One")]
        [string]$ParamOne,
        
        [Parameter(Mandatory, ParameterSetName="Two")]
        [string]$ParamTwo,
        
        [Parameter(Mandatory, ParameterSetName="One")]
        [string]$ParamThree
    )
    # Test-ParamOrder_One "first" "third" 
    # The above command does not work - this is due to ParameterSetName
    # When using ParameterSetName, and you want to be able to supply "parameterless" values
    #    you have to use the "Position = x" attribute, or else PowerShell does not
    #    know which ParameterSet the given param belongs to
    Write-Host $ParamOne
    Write-Host $ParamTwo
    Write-Host $ParamThree
}

function Test-ParamOrder_Two {
    param(
        [Parameter(Mandatory)]
        [string]$ParamOne,
        
        [Parameter(Mandatory)]
        [string]$ParamTwo,
        
        [Parameter(Mandatory)]
        [string]$ParamThree
    )
    # Test-ParamOrder_Two "first" "second" "third"
    # The above command works without the need to specify parameter names
    Write-Host $ParamOne
    Write-Host $ParamTwo
    Write-Host $ParamThree
}

from adsips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.