# 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…

blog

28 Jul 2016 en

![Office 365 – A parameter cannot be found that matches parameter name UserPrincipalName on New-Mailbox](/wp-content/uploads/2016/07/Office-365.png)

[View images (2)](#pf-content-image-1-0)

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.**

```plain
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**

![New-Mailbox PowerShell prompt asking for the missing UserPrincipalName value during interactive mailbox creation.](/wp-content/uploads/2016/07/img_5799f83b7e549.png)

> 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.

```plain
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.

[!\[New-Mailbox PowerShell error showing that the UserPrincipalName parameter is not recognized in this Office 365 command.\](/wp-content/uploads/2016/07/img_5799f8f539ec5.png)](/wp-content/uploads/2016/07/img_5799f8f539ec5.png)

> 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.

[!\[Successful New-Mailbox what-if output after replacing UserPrincipalName with MicrosoftOnlineServicesID.\](/wp-content/uploads/2016/07/img_5799fd576877f.png)](/wp-content/uploads/2016/07/img_5799fd576877f.png)

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

Proper code:

```plain
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.

## Related Projects

Projects that align with this post's tags, categories, and content.

[All projects](/projects/)

Matching projects...

[Back to Blog](/blog)

## Related posts

- [Creating Visual Indicators for spoofed / external emails with PowerShell](/blog/creating-visual-indicators-for-spoofed-external-emails-with-powershell/)
- [No account settings were returned from the Autodiscover response – Microsoft Exchange 2016](/blog/no-account-settings-were-returned-from-the-autodiscover-response-microsoft-exchange-2016/)
- [Microsoft Exchange Approval Assistant – Your message couldn’t be delivered because delivery to this address is restricted to authenticated senders](/blog/microsoft-exchange-approval-assistant-your-message-couldnt-be-delivered-because-delivery-to-this-address-is-restricted-to-authenticated-senders/)

<!-- PowerForge markdown artifact sha256:F7C2FD9849839E7BBC6621C6C15A69E3B4520D9DC152B7287F87883C554DA4AE -->
