How to Use New-MgUser to Create Microsoft 365 Users?

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.

What is New-MgUser?

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.

Why Use New-MgUser?

Using New-MgUser offers several benefits:

  • Automation: Quickly create users in bulk via scripting.
  • Consistency: Ensure all required fields are applied uniformly.
  • Scalability: Ideal for onboarding large teams or syncing external systems.
  • Integration: Easily integrate with CSV files or HR systems.

Cmdlet Syntax

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.

Usage Examples

  1. Basic User Creation
  2. New-MgUser -DisplayName "John Doe" `
    -UserPrincipalName "john.doe@yourdomain.com" `
    -MailNickname "john.doe" `
    -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
    -AccountEnabled 
                                                
  3. Creating a User with GivenName and Surname
  4. 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"
                                                
  5. Creating a User with Department and Office Location
  6. New-MgUser -DisplayName "Mark Johnson" `
    -UserPrincipalName "mark.johnson@yourdomain.com" `
    -MailNickname "mark.johnson" `
    -PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
    -AccountEnabled  `
    -Department "Sales" `
    -OfficeLocation "Building 1"
                                                
  7. Bulk User Creation from CSV
  8. 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
    }
                                                    

CSV File Format

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
                                        

Frequently Asked Questions

  • What roles or permissions are needed to use New-MgUser?
  • You must be assigned a role like User Administrator or Global Administrator in Microsoft Entra ID (Azure AD).

  • What happens if I don’t include AccountEnabled?
  • 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.

  • Can I assign licenses while creating users?
  • No, license assignment requires a separate step using Set-MgUserLicense.

Use Cases

  • New Employee Onboarding: Create users with appropriate department, job title, and office location.
  • Bulk Import from HR Systems: Use CSV import to onboard multiple users in one go.
  • Testing or Demo Tenants: Quickly spin up test users using scripted commands.

Conclusion

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.

Want More Scripts?

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