How to create users in Microsoft 365 with PowerShell

  • Post author:
  • Post category:Main
  • Post last modified:August 7, 2023
  • Reading time:4 mins read

In this post I am going to walk you through how to create and delete user accounts in your Microsoft 365 tenant using PowerShell. Using PowerShell to perform this task is a faster and more efficient method to using the web admin portal, which we did in my previous post, How to create a new user in the Microsoft 365 admin portal.

Creating a user with Powershell

  • Start by opening Powershell as an Administrator
  • You will need to install the MSOnline module, you can do this with the following command. If you already have the MSOnline module installed, you can use the -force parameter to deploy the latest version
Install-Module -Name MSOnline -force
  • Now the module is installed, import the module into your current Powershell session
Import-Module -Name MSOnline
  • Now you will need to connect to your M365 subscription
  • You will be prompted with a new window to login with your Administrator account
  • If you wish to assign a license to your new user on creation, you will need to know the available licensing plans. You can do this using this command
  • Here I am going to create a new user with the following information:
    • Display name: John Doe
    • First Name: John
    • Last name: Doe
    • Username: [email protected]
    • Usage location: UK
    • License: Exchange Online Plan 1
    • Password: Temp123!
New-MsolUser -DisplayName "John Doe" -FirstName John -LastName Doe -UserPrincipalName [email protected] -UsageLocation US -LicenseAssignment ourcloudnetwork77:EXCHANGESTANDARD -Password Temp123!
  • If successful, you should see a similar result:
User creation powershell result
  • If you have assigned an Exchange license to the user, the username set above will also become the primary email address
  • A full list of parameters for creating a new user can be found below:
   [-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>]

Thank you for reading! be sure to head back to our Microsoft 365 Online Administrators Guidebook to progress with your training.

Daniel Bradley

My name is Daniel Bradley and I work with Microsoft 365 and Azure as an Engineer and Consultant. I enjoy writing technical content for you and engaging with the community. All opinions are my own.

Leave a Reply