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
Connect-msolservice
- 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
Get-MsolAccountSku
- 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:
- 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:
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>]
Thank you for reading! be sure to head back to our Microsoft 365 Online Administrators Guidebook to progress with your training.