Managing users is one of the most fundamental tasks for Microsoft 365 administrators. Whether onboarding new employees, managing existing accounts, or handling bulk user imports, a streamlined approach to creating user accounts is essential for efficiency and accuracy.
The New-MgUser cmdlet, part of the Microsoft Graph PowerShell module, allows administrators to automate and simplify the process of adding users to a0020Microsoft 365 environment. This guide walks you through every detail of using the cmdlet, with practical examples and best practices
Microsoft 365 users are accounts that grant individuals access to various Microsoft 365 services such as Exchange Online, Teams, SharePoint, and OneDrive. These accounts can be:
Admins are responsible for creating and managing these user accounts to ensure smooth access and security.
The New-MgUser cmdlet simplifies the process of creating user accounts by allowing admins to:
While the Microsoft 365 Admin Center offers a graphical interface for creating users, New-MgUser is far more efficient for repetitive or large-scale tasks.
Before you can use New-MgUser, you need to install and configure the Microsoft Graph PowerShell module:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.Read.All"
Disconnect-MgGraph
The New-MgUser cmdlet is used to create new user accounts in Microsoft 365. It offers flexibility in assigning attributes like display name, user principal name (UPN), and job title during user creation.
Cmdlet Syntax
New-MgUser -DisplayName <String> -UserPrincipalName <String> -MailNickname <String> -PasswordProfile <PasswordProfile>
The -PasswordProfile parameter is mandatory, as every new user account requires an initial password.
To add a single user with basic details, use:
New-MgUser -DisplayName "John Doe" -UserPrincipalName "john.doe@contoso.com" -MailNickname "johndoe" -PasswordProfile @{password="P@ssw0rd!"; forceChangePasswordNextSignIn=$true}
This command creates a user named John Doe with an enabled account and a temporary password.
For adding multiple users in one script, you can define user details in an array and loop through them:
$users = @( @{ DisplayName="Jane Smith"; UserPrincipalName="jane.smith@contoso.com"; MailNickname="janesmith"; Password="P@ssw0rd1!" }, @{ DisplayName="Mark Taylor"; UserPrincipalName="mark.taylor@contoso.com"; MailNickname="marktaylor"; Password="P@ssw0rd2!" } ) foreach ($user in $users) { New-MgUser -DisplayName $user.DisplayName -UserPrincipalName $user.UserPrincipalName -MailNickname $user.MailNickname -PasswordProfile @{password=$user.Password; forceChangePasswordNextSignIn=$true} }
This script iterates through the array and creates multiple users.
To handle bulk user creation, import user details from a CSV file and use them in a script:
$users = Import-Csv -Path "C:\Users\admin\Documents\users.csv" foreach ($user in $users) { New-MgUser -DisplayName $user.DisplayName -UserPrincipalName $user.UserPrincipalName -MailNickname $user.MailNickname -PasswordProfile @{password=$user.Password; forceChangePasswordNextSignIn=$true} }
This approach is ideal for onboarding large numbers of users.
The New-MgUser cmdlet is a powerful tool for Microsoft 365 administrators, enabling efficient and accurate user creation. Whether you’re adding a single user, creating multiple accounts, or handling bulk imports, this cmdlet simplifies the process and saves time.
By mastering New-MgUser and following best practices, you can streamline user onboarding and ensure a smooth experience for your organization.
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.
© M365Corner. All Rights Reserved.