Creating users in Microsoft 365 is a foundational task for IT administrators. Whether you're onboarding a new employee or provisioning multiple accounts at once, automation using PowerShell can save you time and reduce manual errors. In this guide, we’ll explore how to use the New-MgUser cmdlet from the Microsoft Graph PowerShell module to create users efficiently.
New-MgUser is a Microsoft Graph PowerShell cmdlet used to create new user accounts in Microsoft 365 (Azure Active Directory). It's part of the Microsoft.Graph.Users module, allowing admins to provision users with various attributes such as display name, job title, department, office location, and more.
Using New-MgUser offers several benefits:
New-MgUser -DisplayName <String> -UserPrincipalName <String> -MailNickname <String> -PasswordProfile <IMicrosoftGraphPasswordProfile> -AccountEnabled <Boolean> [-GivenName <String>] [-Surname <String>] [-JobTitle <String>] [-Department <String>] [-OfficeLocation <String>]
Note: In most real-world scenarios, it’s best practice to use the -BodyParameter for complex or bulk creations.
New-MgUser -DisplayName "John Doe" `
-UserPrincipalName "john.doe@yourdomain.com" `
-MailNickname "john.doe" `
-PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
-AccountEnabled
New-MgUser -DisplayName "Jane Smith" `
-UserPrincipalName "jane.smith@yourdomain.com" `
-MailNickname "jane.smith" `
-PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
-AccountEnabled `
-GivenName "Jane" `
-Surname "Smith" `
-JobTitle "Marketing Manager"
New-MgUser -DisplayName "Mark Johnson" `
-UserPrincipalName "mark.johnson@yourdomain.com" `
-MailNickname "mark.johnson" `
-PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
-AccountEnabled `
-Department "Sales" `
-OfficeLocation "Building 1"
Here’s how you can import and create multiple users from a CSV file:
$users = Import-Csv -Path "Users.csv"
foreach ($user in $users) {
$userParams = @{
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
MailNickname = $user.MailNickname
AccountEnabled = $true
PasswordProfile = @{
Password = $user.Password
ForceChangePasswordNextSignIn = $true
}
}
New-MgUser -BodyParameter $userParams
}
Ensure your Users.csv looks like this:
DisplayName,UserPrincipalName,MailNickname,Password
Alice Brown,alice.brown@yourdomain.com,alice.brown,Password123
Bob White,bob.white@yourdomain.com,bob.white,Password123
You must be assigned a role like User Administrator or Global Administrator in Microsoft Entra ID (Azure AD).
The user account may be created in a disabled state or error out depending on the API behavior. Always specify -AccountEnabled $true to ensure usability.
No, license assignment requires a separate step using Set-MgUserLicense.
New-MgUser is a powerful cmdlet for Microsoft 365 admins to create users effectively using Microsoft Graph PowerShell. With support for both individual and bulk creation, it provides the flexibility you need for different business scenarios.
Whether you're creating one user or hundreds, mastering this cmdlet will streamline your user provisioning process.
Explore more practical Graph PowerShell scripts at M365Corner.com and simplify your admin tasks with ready-to-use examples and tools.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex