How to handle missing parameters ...

Welcome Forums General PowerShell Q&A How to handle missing parameters ...

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #91481

    Points: 0
    Rank: Member

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

    Usually at the PS command line, I can type:

    PS> ./reset-password 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 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 -alternate -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.

    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

  • #91495

    Points: 0
    Rank: Member

    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

The topic ‘How to handle missing parameters ...’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort