Artykuł

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

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.

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.

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 „anna.klimza-maslowska@domain.pl” in organizational unit „EURPR06A004.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/organization.onmicrosoft.com”.

Proper code:

Notes

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

Tags: , , , ,

This is a unique website which will require a more modern browser to work! Please upgrade today!