Office 365

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.

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 „anna.klimza-maslowska@domain.pl” 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.

This post was last modified on 28 lipca, 2016 13:53

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

5 dni ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

4 miesiące ago

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

8 miesięcy ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

1 rok ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

1 rok ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

1 rok ago