Bulk Onboard Users from an Excel File Using a PowerShell and Microsoft Graph Script

Prev Next

Create Entra ID accounts, set profile properties, and assign group memberships in a single scripted pass driven by a simple Excel roster.

Complexity: Intermediate. Impact: user-management + automation + entra-id + bulk-operations + onboarding.

Why use this workflow

New-hire onboarding is one of the most repetitive and error-prone tasks in a Microsoft 365 tenant. Creating each user by hand in the admin center means manually entering names, setting temporary passwords, typing department and phone data, and then selecting each group to add the new hire. When HR hands you a batch of starters for the same day, the manual approach is slow, inconsistent, and easy to get wrong.

This workflow describes a reusable PowerShell approach that reads a plain Excel file (columns: Name, Phone, Groups, Department) and onboards every row into Entra ID through the Microsoft Graph PowerShell SDK. The spreadsheet becomes your source of truth: HR fills it in, you run the script, and the tenant is updated.

Run this workflow any time you need to bulk-provision accounts: new-hire waves, intern cohorts, seasonal staff, acquisition onboarding, or migrating users from another identity system where you can export a CSV or XLSX of names, phones, departments, and group memberships.

Expected outcomes

  • A parameterized PowerShell script that bulk-creates Entra ID users from an Excel roster.
  • Each new user provisioned with display name, first and last name, UPN, mail nickname, department, business phone, usage location, and a forced-change temporary password.
  • Each new user added to all groups listed in the Groups column (semicolon-separated), with group IDs cached for efficiency.
  • Idempotent behavior: re-running the script skips existing users and existing group memberships rather than failing.
  • A -WhatIf dry-run mode so that you can preview every create and every group add before you commit.
  • A console summary that shows per-user status (CREATED, EXISTED, FAILED) and per-group outcomes.

Risks and considerations

  • Temporary password handling. Pass the temporary password as a mandatory parameter. Do not hard-code it into the script or check it into source control. Prefer a one-time password generator or Read-Host -AsSecureString in production.
  • UPN collisions. The approach builds UPNs as firstname.lastname@domain. Two users with the same name collide. Add a middle initial or employee ID column for large rosters.
  • No license assignment. This workflow creates accounts and sets usageLocation, but does not assign licenses. Use group-based licensing on the groups that you add users to, or extend the script with Set-MgUserLicense.
  • Group name ambiguity. Groups are resolved by displayName. If two groups share the same name, the first match wins. Use object IDs or mailNickname for disambiguation in larger tenants.
  • Always dry-run first. Run with -WhatIf against the full spreadsheet before the real run. Check the UPNs and group names in the output.
  • Compliance. Entra ID creation events are audited. Make sure your change-management process (ticket ID, HR approval) is attached to the run, and do not commit the Excel roster with PII to a public repository.
  • Rate limits. For large rosters, expect Graph throttling. Add a delay between iterations or batch the requests if needed.

Required permissions

PermissionWhy it's needed
User.ReadWrite.AllCreate new user accounts and set department, phone, and password profile.
Group.ReadWrite.AllResolve groups by display name and add new users as members.
Directory.Read.AllLook up existing users to detect duplicates before creating.

Ask Dex

Paste the prompt into a Dex conversation.

Prompt for IT admins

Onboard the users in the attached Excel file ({file}) into our Microsoft 365 tenant. For each row, create the Entra ID account using domain {domain}, set a temporary password that must be changed at first sign-in, populate department and phone, and add the user to every group listed in the Groups column (semicolon-separated). Skip users that already exist. Give me a summary of who was created and any failures.

Manual steps (admin center)

If you have only one or two users to onboard, the admin center is fine. For anything larger, use the scripted approach.

Step 1: Open the Microsoft 365 admin center

Go to the Microsoft 365 admin center > Users > Active users.

Step 2: Add a user

  1. Select Add a user.
  2. Fill in First name, Last name, Display name, and Username (the part before @).
  3. Choose the domain from the list.
  4. Set an initial password (auto-generated or typed) and select Require this user to change their password when they first sign in.
  5. Select Next.

Step 3: Assign licenses (optional)

Select the Location and select the licenses this user needs, or choose Create user without product license. Select Next.

Step 4: Optional settings: profile info

  1. Expand Profile info.
  2. Enter Job title, Department, Office, Office phone, and Mobile phone as needed.
  3. Select Next, review, and select Finish adding.

Step 5: Add the user to groups

Go to Active users > select the new user > Account tab > Manage groups.

  1. Select Manage groups.
  2. Search for each group by name and select it to add it.
  3. Select Save changes.

Repeat for every new hire. For batches of more than a few users, switch to the PowerShell approach below.

Microsoft Graph API

Each of the steps below is what the PowerShell approach executes per user. You can call them directly with any HTTP client (Postman, curl, a custom app) if you prefer a language other than PowerShell.

1. Check if the user already exists

GET https://graph.microsoft.com/v1.0/users?$filter=userPrincipalName eq 'morgan.bennett@contoso.com'&$select=id,displayName,userPrincipalName

2. Create the user

POST https://graph.microsoft.com/v1.0/users
Content-Type: application/json

{
  "accountEnabled": true,
  "displayName": "Morgan Bennett",
  "givenName": "Morgan",
  "surname": "Bennett",
  "mailNickname": "MorganBennett",
  "userPrincipalName": "morgan.bennett@contoso.com",
  "usageLocation": "US",
  "department": "HR",
  "businessPhones": ["(312) 907-7873"],
  "passwordProfile": {
    "forceChangePasswordNextSignIn": true,
    "password": "{temporary_password}"
  }
}

Returns the new user object including id, which you need for group assignments.

3. Resolve each group by display name

GET https://graph.microsoft.com/v1.0/groups?$filter=displayName eq 'Marketing Internal'&$select=id,displayName

4. Add the user to the group

POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref
Content-Type: application/json

{
  "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}"
}

Returns 204 No Content on success. Returns 400 with One or more added object references already exist if the user is already a member. Treat this as an idempotent success.

Pagination and throttling

For large rosters, expect 429 Too Many Requests responses. Honor the Retry-After header. To reduce the number of calls, you can use POST /$batch.

PowerShell

1. Install prerequisites (one-time)

Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module ImportExcel   -Scope CurrentUser

The ImportExcel module reads .xlsx directly, so no Excel installation is required.

2. Prepare your Excel roster

Create a file with these columns (header row required):

NamePhoneGroupsDepartment
Morgan Bennett(312) 907-7873Marketing Internal; All CompanyHR
Alex Chen(415) 555-0102Engineering; All CompanyEngineering

Multiple groups go in a single cell, separated by semicolons.

3. Approach

Write a script that accepts the Excel path, the domain, and the temporary password as parameters, and supports -WhatIf so that you can run it as a dry run first. Review the dry-run output carefully, then run it for real.

Approach per row

  1. Parse the Name into first and last name, and build a UPN of first.last@domain and a mailNickname.
  2. Call Get-MgUser -Filter to check for an existing account at that UPN.
  3. If the account is missing, call New-MgUser with DisplayName, GivenName, Surname, UserPrincipalName, MailNickname, UsageLocation, Department, BusinessPhones, and a PasswordProfile with ForceChangePasswordNextSignIn = $true.
  4. Split the Groups cell on ;, resolve each name with Get-MgGroup -Filter "displayName eq '...'", cache the ID, and call New-MgGroupMember.
  5. Append a row to an in-memory results list, and print a Format-Table summary at the end.