Scroll Top
Evotec Services sp. z o.o., ul. Drozdów 6, Mikołów, 43-190, Poland

Office 365 – A parameter cannot be found that matches parameter name UserPrincipalName on New-Mailbox

Office 365

Migrating companies from On-Premise setups of Exchange 2010 or Exchange 2013 to cloud Exchange on Office 365 often requires some PowerShell scripting to help speed up the process. Recreating all the users in Office 365 can be done in 2 ways: manually or automatically.

Problem Description

As we prefer automatic way we often end up writing scripts that do this for us, even if it would take the same amount of time to create accounts by hand. But it's way more fun this way.

We've prepared some script that reads the information from old Exchange, exports it to CSV and then we import it from CSV and feed it to New-Mailbox.

New-Mailbox -Alias $mailbox.Alias -Name $mailbox.Name -DisplayName $mailbox.DisplayName -ResetPasswordOnNextLogon $true -Password $temporaryPassword -WhatIf

It's simple and effective. But when you run this command you're asked to give full UserPrincipalName

cmdlet New-Mailbox at command pipeline position 1

Supply values for the following parameters:

UserPrincipalName:

While it could be fun to type this for each user it's not something we wanted. So we simply update the command with UserPrincipalName and run the command again.

New-Mailbox -Alias $mailbox.Alias -Name $mailbox.Name -DisplayName $mailbox.DisplayName -ResetPasswordOnNextLogon $true -Password $temporaryPassword -UserPrincipalName $upn -WhatIf

Unfortunately for us… it doesn't work.

A parameter cannot be found that matches parameter name ‘UserPrincipalName'.

    + CategoryInfo          : InvalidArgument: (:) [New-Mailbox], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,New-Mailbox

    + PSComputerName        : ps.outlook.com

It seems that New-Mailbox command doesn't have UserPrincipalName option yet it asks for one.

Solution

The trick is to use MicrosoftOnlineServicesID instead of UserPrincipalName (UPN). After replacing UPN with MicrosoftOnlineServicesID everything seems to work just fine.

Name: Anna Klimza-Masłowska FirstName: Anna LastName: Klimza-Masłowska

WARNING: After you create a new mailbox, you must go to the Office 365 Admin Center and assign the mailbox a license, or it will be disabled after the grace period.

What if: Creating mailbox “Anna Klimza-Masłowska” with User Principal Name “[email protected]” in organizational unit “EURPR06A004.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/organization.onmicrosoft.com”.

Proper code:

New-Mailbox -Alias $mailbox.Alias -Name $mailbox.Name -DisplayName $mailbox.DisplayName -ResetPasswordOnNextLogon $true -Password $temporaryPassword -MicrosoftOnlineServicesID $upn -FirstName $firstName -LastName $lastName -WhatIf

Notes

As suggested by Microsoft own command don't forget to assign Office 365 license after you're done creating mailboxes.

Posty powiązane

Zostaw komentarz

You must be logged in to post a comment.