How to handle missing parameters ...

This topic contains 2 replies, has 2 voices, and was last updated by  Larry Keyes 4 months ago.

  • Author
    Posts
  • #91481

    Larry Keyes
    Participant

    Hi... I have an Office365 password reset script that takes up to three parameters.
    A mandatory userprincipalname, ie. "myron.kapoodle@project.com
    An optional alternate email address i.e. mkapoodle@gmail.com
    An optional ticket number of the support ticket.

    Usually at the PS command line, I can type:

    PS> ./reset-password myron.kapoodle@project.com mkapoodle@gmail.com 3840 
    

    But sometimes I don't have the alternate eMail address. I'd like to be able to supply the UPN and the ticket ID only, thereby sliding the ticketID which is usually the third parameter into "second place".

    PS>./reset-password myron.kapoodle@project.com 3840 
    

    Or sometimes I don't have the ticket ID either.
    Is there a way to deal with all three possibilities while avoiding named parameters?
    If possible I'd like to avoid having to type.

    ./reset-password -UPN myron.kapoodle@project.com -alternate mkapoodle@gmail.com -ticketID 3894 
    

    Here is how I'm handling it now. I can either supply all three parameters, or just the one,
    and if I just have the one I go and manually clean up the ticket.

    [Cmdletbinding()]
    param (
        [Parameter(Position=0, mandatory=$True, ValueFromPipeline=$True)]
        [string] $UpName,
        [Parameter(Position=1, ValueFromPipeline=$True)]
        [string] $PrivateEMail,
        [Parameter(Position=3, ValueFromPipeline=$True)]
        [string] $FDTicketID)
    
  • #91484

    Don Jones
    Keymaster

    May I ask what the problem is with providing named parameters?

  • #91495

    Larry Keyes
    Participant

    Well, I'm trying to avoid typing them. I wasn't sure if it was possible to have "shifting positional parameters". (I just made that up).

    Or maybe multiple parameter sets which account for the three different possibilities?

    — L

You must be logged in to reply to this topic.