Author Posts

January 15, 2018 at 3:21 pm

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)

January 15, 2018 at 3:34 pm

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

January 15, 2018 at 4:02 pm

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