Share via


"Invalid user name" when you try to create a user name that contains a special character in Microsoft 365

Problem

When you create a user name that contains a special character in Microsoft 365, you receive one of the following error messages:

Within the Microsoft 365 portal

Invalid user name
Only letters and numbers are allowed. No spaces.

Within Microsoft Azure Active Directory module for Windows PowerShell

New-MsolUser : Invalid value for parameter. Parameter Name: UserPrincipalName.
At line:1 char:13

Within Exchange Online Windows PowerShell

A Windows Live error occurred while provisioning for "user+invalid_characters@contoso.com". The e-mail name contains invalid characters.

Note

Azure AD and MSOnline PowerShell modules are deprecated as of March 30, 2024. To learn more, read the deprecation update. After this date, support for these modules are limited to migration assistance to Microsoft Graph PowerShell SDK and security fixes. The deprecated modules will continue to function through March, 30 2025.

We recommend migrating to Microsoft Graph PowerShell to interact with Microsoft Entra ID (formerly Azure AD). For common migration questions, refer to the Migration FAQ. Note: Versions 1.0.x of MSOnline may experience disruption after June 30, 2024.

Cause

This behavior occurs because certain special characters aren't permitted in user names that you create in Microsoft 365. These special characters include but aren't limited to the following characters:

Property UserPrincipalName requirements
Characters allowed
  • A – Z
  • a - z
  • 0 – 9
  • ' . - _ ! # ^ ~
Characters not allowed
  • Any @ character that's not separating the username from the domain.
  • Can't contain a period character (.) immediately preceding the @ symbol.
  • Can't contain an ampersand (&) character in the user name.
Length constraints
  • The total length must not exceed 113 characters.
  • There can be up to 64 characters before the @ symbol.
  • There can be up to 48 characters after the @ symbol.

However, the following exceptions apply:

  • An underscore (_) is permitted anywhere in the user name, including at the beginning or end of the name.
  • When you create a group, the number sign (#) can be used as part of the group's name. However, the email address you create for a distribution group or shared mailbox can't use the # sign.

Solution

When you create a new user in Microsoft 365, make sure that you don't use any of the special characters that are listed in the Cause section.

Still need help? Go to Microsoft Community.