Create multiple Test Lab Users In Office 365 Using PowerShell

In this article I’ll show you how I create multiple Test Users In Office 365 using a very Powerful PowerShell script.

Like always, Before you start, Install the Windows PowerShell Module for Office 365 and connect to Office 365 using PowerShell

Once ready copy the cmdlet below to ISE and run it.

The cmdlet will create 20 test users starting with the name User and the Number.

To change it to create more or less or the name modify the code:

foreach ($number in 11..20) { New-MsolUser -UserPrincipalName "user$number@mycompany.com" -DisplayName "User $number" }

Once the script Is completed, I can view all the new account using the cmdlet below:

Get-MsolUser -UnlicensedUsersOnly

Next I’ll set the location all the new unlicensed Users:

Get-MsolUser -UnlicensedUsersOnly | Set-MsolUser -UsageLocation us

And assign a license:

Get-MsolUser -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses (Get-MsolAccountSku).AccountSkuId

Posted

in

by