This content is part of the Essential Guide: The essential admin's guide to Office 365 PowerShell
Manage Learn to apply best practices and optimize your operations.

Create 10, 100 or more Office 365 accounts with PowerShell

Administrators who need to create accounts for new employees can save time by using PowerShell scripts to read and import data from a CSV file straight into Office 365.

Why repeat the same task dozens or hundreds of times in the Office 365 Admin Center?

You probably provision new Office 365 accounts on a regular basis if you manage the email platform for your organization. This is possible via the Office 365 Admin Center portal or via PowerShell. If you need to create one or two user accounts, use the Admin Center portal. However, if you find yourself building dozens or hundreds of accounts on a regular basis, learn to script the process with PowerShell.

The Office 365 administrator can use PowerShell to read some kind of data source, such as a CSV file. We can then read each row of this CSV file representing various employees and pass each one to the New-MsolUser cmdlet to seamlessly build one, 10 or 1,000 Office 365 accounts at one time.

You'll need the Microsoft Online Services Sign-In Assistant and the Microsoft Azure Active Directory (AD) PowerShell Module installed. These are both Windows Installer MSI files. Download and install them, accepting the defaults. You will only have to install these once.

Once you install the prerequisite software, bring up a PowerShell session and run Connect-MsolService. This will prompt you for your Office 365 credentials and connect you.

Add new employees to Office 365

We can now begin to process those employees in the CSV file. PowerShell has a built-in cmdlet called Import-CSV to read each row of the CSV file into memory, and save each row as an object with all the properties you'd expect; you simply point Import-CSV to your list of new employees.

The CSV file that you'll get from human resources may simply have the first name and last name of a group of new employees (see the figure) from which you'll make new Office 365 user accounts. We need more fields than first and last name, fields which we can construct on the fly with PowerShell scripts.

Employees to add to Office 365.
Figure. A typical employee CSV file from your organization might look like this. These are the employees you'll add to Office 365.

Bring in the CSV rows in memory, assigning them to the $users variable.

$users = Import-CSV –Path C:\Users.csv

Now that each employee's first and last name are stored in the $users variable, loop through each of those employees and run the New-MsolUser cmdlet for each one.

Need to create users in bulk in Exchange Online rather than Office 365? The process is similar with a few key differences.

Because the CSV just contains the employee's first and last name, construct a few parameters for the New-MsolUser cmdlet. These are the UserPrincipalName and the DisplayName that will be associated with the Office 365 accounts. The UserPrincipalName needs to be in the format of first initial/last name @ my domain. Build this by assigning a variable $firstInitLastName that is the employee's first initial/last name and combining that with the domain name. Also, the display name needs to be first name/last name with a space in between, so build that via a string as well.

$domain = ''

foreach ($user in $users) {

    $firstInitLastName = '{0}{1}' –f $user.FirstName.SubString(0,1),$user.LastName

    $newUserParams = @{

         'FirstName' = $user.FirstName

         'LastName' = $user.LastName

         'UserPrincipalName' = "[email protected]$domain"

         'DisplayName' = "$($user.FirstName) $($user.LastName)"

         'Password' = '[email protected]'


    New-MsolUser @newUserParams


Once this reads each of the users in the $users variable, you should now have new Office 365 accounts created for each employee that was in your original CSV file.

If you'd rather not store the password in your script, you can store passwords encrypted on the file system.

Author's Note: this article is based on using version 0.98 of the Azure AD module.

Next Steps

The worst email problems Office 365 admins face

Admins' must-know apps for Office 365 and Exchange

A plan to merge accounts on Office 365

Dig Deeper on Office 365 and Microsoft SaaS setup and management