Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitThis guide demonstrates how to use the New-MgUser cmdlet in Microsoft Graph PowerShell to create Microsoft 365 users. Learn how to set properties like display name, user principal name, and password with examples for single and bulk creation
The New-MgUser cmdlet in Microsoft Graph PowerShell is an essential tool for administrators to create new users in Microsoft 365. This cmdlet allows for detailed user profile customization, making it a versatile option for managing user accounts. In this article, we will explore the basics of the New-MgUser cmdlet, provide usage examples, address possible errors and solutions, and offer tips for effective use.
New-MgUser -DisplayName <String> -UserPrincipalName <String> -MailNickname <String> -PasswordProfile <PSObject> -AccountEnabled <Boolean>
Creating user using only the basic user attributes like DisplayName, UserPrincipalName, MailNickname and Password.
New-MgUser -DisplayName "John Doe" -UserPrincipalName "john.doe@yourdomain.com" -MailNickname "john.doe" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled
Adding additional user information like -Surname and -JobTitle.
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"
Adding additional user information like -Department and -OfficeLocation details.
New-MgUser -DisplayName "Mark Johnson" -UserPrincipalName "mark.johnson@yourdomain.com" -MailNickname "mark.johnson" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled -Department "Sales" -OfficeLocation "Building 1"
Adding additional user information like -MobilePhone and -BusinessPhones details.
New-MgUser -DisplayName "Alice Brown" -UserPrincipalName "alice.brown@yourdomain.com" -MailNickname "alice.brown" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled -MobilePhone "+1234567890" -BusinessPhones @("+0987654321")
Adding additional user information like -UsageLocation and -PreferredLanguage details.
New-MgUser -DisplayName "Tom Wilson" -UserPrincipalName "tom.wilson@yourdomain.com" -MailNickname "tom.wilson" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled -UsageLocation "US" -PreferredLanguage "en-US"
This is particularly useful for onboarding large teams or migrating users from another system.
$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
}
CSV File Structure:
If the script is run directly or from a .ps1 file you should get the list of newly created users as the output.
Creates a user account that is initially disabled (often used for service-level identities or staged provisioning), with a password set but login prevented due to accountEnabled = $false.
$params = @{
accountEnabled = $false
displayName = "Service Account - No Login"
mailNickname = "svcaccount1"
userPrincipalName = "svcaccount1@yourdomain.com"
usageLocation = "US"
passwordProfile = @{
forceChangePasswordNextSignIn = $false
password = "S3cureTempP@ssword!"
}
}
New-MgUser -BodyParameter $params
Error | Solution |
Invalid PasswordProfile Object | Ensure the PasswordProfile object is formatted correctly as a hashtable with the required properties. |
UserPrincipalName Already Exists | Ensure the UserPrincipalName is unique and not already in use. |
Password Does Not Meet Requirements | Ensure that the password meets the complexity requirements or the tenant password policy. |
Invalid UPN Suffix |
Validate the UPN suffix before creating the user. Example:
|
$Body = @{
displayName = "John Doe"
userPrincipalName = "johndoe@domain.com"
mailNickname = "johndoe"
accountEnabled = $true
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = "StrongPassword123!"
}
}
New-MgUser -BodyParameter $Body
DisplayName,UserPrincipalName,MailNickname,Password
John Doe,johndoe@domain.com,johndoe,StrongPassword123!
Jane Smith,janesmith@domain.com,janesmith,AnotherPassword123!
$Users = Import-Csv -Path "C:\Path\To\File.csv"
foreach ($User in $Users) {
$Body = @{
displayName = $User.DisplayName
userPrincipalName = $User.UserPrincipalName
mailNickname = $User.MailNickname
accountEnabled = $true
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = $User.Password
}
}
New-MgUser -BodyParameter $Body
}
New-MgUser -DisplayName "Mark Johnson" -UserPrincipalName "mark.johnson@yourdomain.com" -MailNickname "mark.johnson" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled -Department "Sales" -OfficeLocation "Building 1"
New-MgUser -DisplayName "Alice Brown" -UserPrincipalName "alice.brown@yourdomain.com" -MailNickname "alice.brown" -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} -AccountEnabled -MobilePhone "+1234567890" -BusinessPhones @("+0987654321")
New-MgUser
, the following properties are mandatory:
DisplayName
UserPrincipalName
PasswordProfile
AccountEnabled
MailNickname
400 Bad Request
or a validation error during user creation.
New-MgUser
can be passed directly, the passwordProfile
must be provided as a nested hashtable. Using a hashtable via $params
is the preferred approach — especially useful when automating or bulk-creating users.
$params = @{
accountEnabled = $true
displayName = "Adele Vance"
mailNickname = "adelev"
userPrincipalName = "adelev@contoso.com"
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = "Xw3lP@ssword!"
}
}
New-MgUser -BodyParameter $params
This approach improves readability and scales better in scripts involving multiple users.
New-MgUser
to activate services like Exchange, Teams, or SharePoint for the new user.usageLocation
property correctly is critical when creating users, as it determines what Microsoft 365 services are available in that region.usageLocation
can lead to license assignment errors or service restrictions.
The New-MgUser cmdlet is a powerful tool for creating new users in Microsoft 365. By understanding the syntax, leveraging various parameters, and addressing common errors, administrators can effectively manage user creation. Follow the examples and tips provided to enhance your user management process in Microsoft 365.
accountEnabled, displayName, mailNickname, userPrincipalName
, and passwordProfile
. The payload must be passed in JSON format.
Create a Single User
# Define the user object to be created
$userPayload = @{
accountEnabled = $true
displayName = "John Sample"
mailNickname = "johnsample"
userPrincipalName = "john.sample@yourtenant.onmicrosoft.com"
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = "Xyz@123456"
}
}
# Convert to JSON and invoke Graph API
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/users" -Body ($userPayload | ConvertTo-Json -Depth 10)
Create Users in Bulk from CSV
# Sample CSV headers: displayName, mailNickname, userPrincipalName, password
$users = Import-Csv -Path "C:\Users\admin\Documents\new-users.csv"
foreach ($user in $users) {
$userPayload = @{
accountEnabled = $true
displayName = $user.displayName
mailNickname = $user.mailNickname
userPrincipalName = $user.userPrincipalName
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = $user.password
}
}
# Create the user
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/users" -Body ($userPayload | ConvertTo-Json -Depth 10)
}
Note: Make sure the passwords in the CSV meet the organization’s password policy.
Required Permissions
To create users via the Graph API, you must have one of the following:
Graph API Documentation
👉 POST /users - Microsoft Graph v1.0© m365corner.com. All Rights Reserved. Design by HTML Codex