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.
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
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"
Prepare a CSV file containing the details of the users you wish to create. Here’s an example of how the CSV might look:
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.
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.
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:
© m365corner.com. All Rights Reserved. Design by HTML Codex