"A user with this name could not be found" when resetting a password for a user in Microsoft 365

Problem

When you try to reset a password for a user in Microsoft 365, you receive the following message:

A user with this name could not be found. They may have been deleted.

Solution

To resolve this issue, use Microsoft Azure Active Directory module for Windows PowerShell to set the user principal name (UPN) to the default domain. Then, change the user principal name back to use the vanity domain. To do this, follow these steps:

  1. Start Azure Active Directory module for Windows PowerShell, and connect to Microsoft Entra ID.

    Note

    For more info about Azure Active Directory module for Windows PowerShell, go to the following Microsoft website: Microsoft Entra Cmdlets.

  2. Change the UPN of the user to the default domain. To do this, run the following command:

    Set-MsolUserPrincipalName -UserPrincipalName [ExistingUPN] -NewUserPrincipalName [NewUPN]
    

    For example, use this command:

    Set-MsolUserPrincipalName -UserPrincipalName johnsmith@contoso.com -NewUserPrincipalName johnsmith@contoso.onmicrosoft.com
    
  3. Change the UPN of the user back to the original domain. To do this, run the following command:

    Set-MsolUserPrincipalName -UserPrincipalName [ExistingUPN] -NewUserPrincipalName [NewUPN]
    

    For example, use this command:

    Set-MsolUserPrincipalName -UserPrincipalName johnsmith@contoso.onmicrosoft.com -NewUserPrincipalName johnsmith@contoso.com
    
  4. Reset the password again.

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.

Still need help? Go to Microsoft Community.