How to Create Bulk Users in Office 365 Using Graph PowerShell?

Creating bulk users in Microsoft 365 (Office 365) is an important M365 administrative task. This can be done using a PowerShell SDK called Graph PowerShell. This module gives PowerShell access to all the Microsoft Graph APIs and has many Microsoft 365 management-specific cmdlets. You can do bulk management operations on M365 identities, automate management of resources like Entra or Teams, or get custom reports – all from the comfort of your PowerShell command line.

Step 1: Install the Microsoft Graph PowerShell Module

First, you need to install the Microsoft Graph PowerShell SDK if you haven't already. Open PowerShell as an administrator and run the following command: Install-Module -Name Microsoft.Graph -Scope CurrentUser

Step 2: Authenticate

Authenticate to Microsoft Graph with an account that has the necessary permissions to create users in your tenant by running the following command: Connect-MgGraph -Scopes "User.ReadWrite.All"

Step 3: Prepare User Data

Prepare a CSV file containing the details of the users you wish to create. Here’s an example of how the CSV might look:



Step 4: Create a Script to Read CSV and Create Users

Create a PowerShell script that reads the CSV file and creates the users. Here’s a basic script that does this:

Note: Ensure you pass the path of the CSV file to Import-Csv cmdlet. In the above case, the path is not specified because the script was executed after getting to the script file’s location as shown in the image below.


Step 5: Run the Script

Execute the script in PowerShell. This will read each row from the CSV file and create a new user in Office 365 using the Microsoft Graph API.

To execute the PowerShell script saved in the .ps1 file, navigate to the location where the .ps1 file is located, type in the ./<filename.ps1> in the PowerShell console and hit Enter. The users get created and listed in the console as shown in the image below.



Step 6: Verify User Creation

Verify that the users have been created either by logging into the Office 365 admin center or executing the Get-MgUser Graph PowerShell command to list users:


Additional Tips

  • Always test your script in a development environment before running it in production.
  • Regularly review and update the permissions and roles required for your scripts as Office 365 policies and settings can change.
  • Handle errors and exceptions in your scripts to manage users that might not be created due to issues like duplicate usernames or non-compliance with password policies.
  • Always refer Microsoft Graph PowerShell documentation to stay updated about any changes that happen overtime.

Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex