Home » Office 365 » New-MsolUser – Create a New User Account in Office 365

New-MsolUser – Create a New User Account in Office 365

The New-MsolUser cmdlet in PowerShell creates a new user account in Microsoft Office 365.

The syntax to add a new user account in Azure Active Directory is given below.

New-MsolUser
   [-ImmutableId <String>]
   [-UserPrincipalName <String>]
   [-BlockCredential <Boolean>]
   [-City <String>]
   [-Country <String>]
   [-Department <String>]
   [-DisplayName <String>]
   [-Fax <String>]
   [-FirstName <String>]
   [-LastName <String>]
   [-LastPasswordChangeTimestamp <DateTime>]
   [-MobilePhone <String>]
   [-Office <String>]
   [-PasswordNeverExpires <Boolean>]
   [-PhoneNumber <String>]
   [-PostalCode <String>]
   [-PreferredDataLocation <String>]
   [-PreferredLanguage <String>]
   [-SoftDeletionTimestamp <DateTime>]
   [-State <String>]
   [-StreetAddress <String>]
   [-StrongPasswordRequired <Boolean>]
   [-Title <String>]
   [-UsageLocation <String>]
   [-AlternateEmailAddresses <String[]>]
   [-StrongAuthenticationMethods <StrongAuthenticationMethod[]>]
   [-AlternateMobilePhones <String[]>]
   [-StrongAuthenticationRequirements <StrongAuthenticationRequirement[]>]
   [-StsRefreshTokensValidFrom <DateTime>]
   [-UserType <UserType>]
   [-Password <String>]
   [-LicenseOptions <LicenseOption[]>]
   [-ForceChangePassword <Boolean>]
   [-LicenseAssignment <String[]>]
   [-TenantId <Guid>]
   [<CommonParameters>]

In this article, we will discuss how to use the New-MsolUser cmdlet in PowerShell to create a new user account in Office 365 and assign a license to the user.

How to Create a New User in Office 365 with PowerShell

To create a new user account in Office 365 with PowerShell, use the New-MsolUser cmdlet.

New-MsolUser -UserPrincipalName "[email protected]" -DisplayName "Bob Allen" -FirstName "Bob" -LastName "Allen" -UsageLocation "US"

This command creates a new user with the display name “Bob Allen“. A random password is generated for the user.

Create a new user in Office 365
New-MsolUser in Office 365

The output of the New-MsolUser cmdlet includes the following properties.

  • Password: The New-MsolUser cmdlet generates a random password for the user.
  • UserPrincipalName: The unique user principal name of the user.
  • DisplayName: The display name of the user.
  • isLicensed: Indicates if the license is assigned to the user.

The -LicenseAssignment parameter is deprecated. If you try to assign the user a license with the New-MsolUser cmdlet, you will get the following warning and error message.

WARNING: This licensing cmdlet has been retired. Please update to MS Graph Set-MgUserLicense: https://aka.ms/mguserlicense

PS C:\> New-MsolUser -UserPrincipalName "[email protected]" -DisplayName "Bob Allen" -FirstName "Bob" -LastName "Allen" -UsageLocation "US" -LicenseAssignment "shellgeeklab:ENTERPRISEPACK"                                         

WARNING: This licensing cmdlet has been retired. Please update to MS Graph Set-MgUserLicense: https://aka.ms/mguserlicense

New-MsolUser : Unknown error occurred.
At line:1 char:1
+ New-MsolUser -UserPrincipalName "[email protected] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.OperationNotAllowedException,Microsoft.Online.Admi
   nistration.Automation.NewUser

How to Create a User and Assign Preferred Data Location

To create a user and assign a preferred data location in Office 365, use the New-MsolUser cmdlet in PowerShell.

New-MsolUser -UserPrincipalName "[email protected]" -DisplayName "Peter Arthur" -FirstName "Peter" -LastName "Arthur" -PreferredDataLocation "EUR" 

This command creates a user with the user principal name “[email protected]“, the display name is “Peter Arthur” and the preferred data location is “EUR“.

The New-MsolUser cmdlet in PowerShell randomly generates a password and assigns it to the user.

The output of the above command is given below.

PS C:\> New-MsolUser -UserPrincipalName "[email protected]" -DisplayName "Peter Arthur" -FirstName "Peter" -LastName "Arthur" -PreferredDataLocation "EUR"                                                                        
Password UserPrincipalName                         DisplayName  isLicensed
-------- -----------------                         -----------  ----------
Waz60363 [email protected] Peter Arthur False


PS C:\>                                          

Conclusion

I hope the above article on how to use the New-MsolUser cmdlet in PowerShell to create a new user and assign the properties to him in Office 365 is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

Get-MsolUser

Set-MsolUser

Remove-MsolUser

Restore-MsolUser