How to: create batch of test users in Office 365 with PowerShell

During testing Office 365, one often need to create several user accounts. Those user accounts can afterwards be assigned different permission levels to various Office 365 services, and used for testing across Office 365 services.

It is possible to create those accounts using Office 365 tenant admin pages manually, or to import CSV file with user accounts using wizard. There is also third option - to use PowerShell.

In our scenario, we need to create several accounts with as little effort as possible. All accounts should be unique, yet still easy recognizable. For creation of user accounts in Office 365 we are using New-MsolUser cmdlet which is a part of Azure Active Directory Module for Windows PowerShell. For New-MsolUser cmdlet, it is required that -UserPrincipalName and -DisplayName parameters are populated. All other parameters are optional. As part of user creation process, we can assign licence to an user - all with same cmdlet. All test users will have same password, and password expiration will be disabled. To accomplish all this, we can use parameters of the New-MsolUser cmdlet:
-Password <passwordString>
To set password of the user we are going to create
-PasswordNeverExpires $true
To configure that password never expires for our test users
-LicenseAssignment <some of available licenses in tenant>
Available licences for a tenant can be retrieved by executing Get-MsolAccountSku cmdlet

We will also use "for" loop in PowerShell to execute New-MsolUser cmdlet for each new test user we need to create.

Here is full sequence of PowerShell commands:

Connect-MsolService  
Get-MsolAccountSku    
for($i=1; $i -le 10; $i++){
New-MsolUser -UserPrincipalName "user$i@mytenant.onmicrosoft.com" -Password "pass@word1" -PasswordNeverExpires $true
-FirstName "User" -LastName $i -DisplayName "User $i" -UsageLocation "BA"
-LicenseAssignment "LicenceNameRetrievedInPreviousCommand"
}

More info and downloads: