Bulk Create M365 Users, Assign Licenses, and Export Credentials CSV

Prev Next

Create a cohort of Microsoft 365 users, assign licenses and group membership, and export a credentials CSV for secure handoff.

Complexity: Intermediate. Impact: user-management + provisioning + licensing + automation + onboarding.

Why use this workflow

This workflow handles end-to-end bulk onboarding for a cohort of new Microsoft 365 users, such as a new team, pilot group, contractor batch, or beta user cohort. Creating users one by one in the admin center is slow and error-prone when you also need to assign licenses, add group memberships, delegate directory roles, and hand credentials back to the requester.

Run this when you need to:

  • Onboard a batch of users in a single operation
  • Ensure consistent attributes (department, usage location, license SKU) across the cohort
  • Produce a CSV of initial passwords for secure handoff to the requesting manager or the users themselves
  • Assign the same directory role or group membership to all users in the batch

The workflow creates each user with a randomly generated password, forces a password change on first sign-in, assigns an available SKU (for example E5, Business Premium, or Developer), adds each user to a target group, optionally grants a directory role, and exports a credentials.csv file for one-time download.

Expected outcomes

  • New user accounts created in Microsoft Entra ID with consistent attributes (displayName, userPrincipalName, givenName, surname, department, usageLocation)
  • A license assigned to each user from the specified SKU
  • All users added as members of the target security or Microsoft 365 group
  • Directory role granted (optional), for example User Administrator, to each user
  • A downloadable CSV file with columns Name, Email/UPN, Initial Password for secure handoff
  • Force change password on next sign-in set on every account, so initial passwords are one-time use

Risks and considerations

  • CSV contains plaintext passwords. Treat the output file as a secret. Deliver it through a secure channel (password manager vault, encrypted email, or a private chat with expiration) and delete the local copy after handoff.
  • Do not reuse the CSV. Once users sign in and change passwords, the values in the file are stale. Regenerate if needed.
  • License availability. Check consumedUnits against prepaidUnits.enabled on the target SKU before you run. The process fails partway through if the tenant runs out of seats.
  • UPN domain must be verified. If you use a custom domain in the UPN, it must be verified on the tenant (isVerified: true) or user creation returns 400 Bad Request.
  • Usage location is required for licensing. Set the usageLocation attribute (ISO 3166-1 alpha-2, for example US, GB, or DE) before calling assignLicense, or the call returns an error.
  • Directory role assignment is privileged. Granting User Administrator or a similar role is a privileged action. Confirm the business justification and log the change in your change-management system.
  • Avoid hardcoding passwords in scripts. Generate them at runtime and never persist them outside the CSV artifact.
  • Idempotency. Re-running with the same UPNs fails because the users already exist. Add a pre-check if you need re-runnable behavior.

Required permissions

PermissionWhy it's needed
User.ReadWrite.AllCreate user accounts, set password profiles, update attributes
Directory.ReadWrite.AllAssign licenses and directory roles
Group.ReadWrite.AllAdd users to the target group
Organization.Read.AllList subscribed SKUs to find the license skuId
RoleManagement.ReadWrite.DirectoryAssign directory roles such as User Administrator

Ask Dex

Paste the prompt into a Dex conversation.

Prompt for IT admins

Onboard the following users to our M365 tenant: {user_list}. For each user: create the account with department '{department}', assign an available {license_sku} license, add them to the '{group_name}' group, and assign the '{directory_role}' directory role. Force password change on first sign-in. Generate a CSV with Name, Email/UPN, and Initial Password and give me the download link.

Manual steps (admin center)

The admin center supports bulk creation through CSV upload. This is the best GUI path when you have several users.

Step 1: Prepare your input CSV

Create a CSV with the columns the Microsoft 365 admin center requires:

User name,First name,Last name,Display name,Job title,Department,Office number,Office phone,Mobile phone,Fax,Address,City,State or province,ZIP or postal code,Country or region
{user1_upn},{first1},{last1},{display1},,{department},,,,,,,,,{country}
{user2_upn},{first2},{last2},{display2},,{department},,,,,,,,,{country}

Step 2: Upload the CSV

  1. Sign in to the Microsoft 365 admin center as a Global Administrator or User Administrator.
  2. Go to Users > Active users > Add multiple users.
  3. Select Upload a CSV file and select your prepared file.
  4. Under Set user settings, choose the Sign-in status (Allow user to sign in) and the Product licenses (your target SKU).
  5. Select Next, review the summary, and select Create users.
  6. Microsoft 365 generates temporary passwords and offers a Download results CSV. This is your credentials file. Download it immediately.

Step 3: Add users to a group

  1. Go to Teams & groups > Active teams & groups.
  2. Open the target group (or create a new one with Add a group).
  3. Go to the Members tab > View all and manage members > Add members.
  4. Search for and add each new user.

Step 4: Assign a directory role (optional)

  1. Go to the Microsoft Entra admin center > Identity > Roles & admins > Roles & admins.
  2. Search for the target role (for example User Administrator) and open it.
  3. Select Add assignments, select the new users, and confirm.

Step 5: Secure handoff

Store the downloaded credentials CSV in a password manager or encrypted vault, share it with the requester through a secure channel, and delete your local copy.

Microsoft Graph API

The Graph API flow for each user is: create, assign license, add to group, assign role. Wrap these calls in a loop over your input list.

1. Discover prerequisites (once)

Get the SKU id for the license you want to assign:

GET https://graph.microsoft.com/v1.0/subscribedSkus

In the response, find the entry whose skuPartNumber matches your target license and note its skuId GUID.

Get the group id:

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

Get the directory role id (activate the role template first if it is not already active):

GET https://graph.microsoft.com/v1.0/directoryRoles

Find the entry with displayName: "User Administrator" (or your target role) and note its id.

2. Create each user

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

{
  "accountEnabled": true,
  "displayName": "{display_name}",
  "givenName": "{given_name}",
  "surname": "{surname}",
  "mailNickname": "{mail_nickname}",
  "userPrincipalName": "{user_upn}",
  "department": "{department}",
  "usageLocation": "{usage_location}",
  "passwordProfile": {
    "forceChangePasswordNextSignIn": true,
    "password": "{randomly_generated_password}"
  }
}

The 201 Created response returns the new user's id (GUID). Capture it for the next steps.

3. Assign a license

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

{
  "addLicenses": [ { "skuId": "{skuId}" } ],
  "removeLicenses": []
}

4. Add to group

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

{
  "@odata.id": "https://graph.microsoft.com/v1.0/users/{userId}"
}

5. Assign directory role (optional)

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

{
  "@odata.id": "https://graph.microsoft.com/v1.0/users/{userId}"
}

6. Build the credentials CSV

As you iterate, append displayName,userPrincipalName,password to an in-memory buffer, then write the buffer to a .csv file at the end of the batch. Do not persist passwords anywhere else.

Throttling: Graph rate limits apply. For large batches, pace your requests and honor any Retry-After header, or use $batch to group operations.

PowerShell

The Microsoft.Graph PowerShell SDK provides typed cmdlets for all the Graph calls above. Build a script that accepts a CSV of users, a license SKU part number, a target group, and an optional directory role, then writes a credentials CSV.

Prerequisites

  • PowerShell 7 or later (recommended) or Windows PowerShell 5.1
  • The Microsoft Graph PowerShell modules:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • A Global Administrator account, or a combination of User Administrator, License Administrator, and Groups Administrator

Input CSV format (users.csv)

DisplayName,GivenName,Surname,MailNickname,UserPrincipalName
{display1},{first1},{last1},{nickname1},{user1_upn}
{display2},{first2},{last2},{nickname2},{user2_upn}

Approach

  1. Connect to Graph with the required scopes.
  2. Resolve the SKU id, the group id, and (optionally) activate and resolve the directory role.
  3. For each input row:
    • Generate a cryptographically random password.
    • Create the user with forceChangePasswordNextSignIn set to $true.
    • Assign the license.
    • Add the user to the group.
    • Assign the directory role (if specified).
    • Append Name,Email,InitialPassword to the output CSV.
  4. Write a summary and the path to the credentials CSV.

Catch and log errors on individual users, and continue with the remaining users rather than failing the whole batch.