Provision · 1 tool

Assign licences in bulk from a CSV

Summary

Assigns a licence to every user in a CSV, sets the usage location first when it is missing, and optionally disables service plans such as Exchange Online for users who are waiting for a mailbox migration.

Implementation

Choose your tool. Your choice is remembered on other samples.

Microsoft Graph PowerShell
Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All -NoWelcome
$sku = Get-MgSubscribedSku -All | Where-Object SkuPartNumber -eq "SPE_E3"
# Optional: keep Exchange Online off until the mailbox has migrated
$disabled = $sku.ServicePlans | Where-Object ServicePlanName -like "EXCHANGE_S_*" | Select-Object -ExpandProperty ServicePlanId

Import-Csv .\users.csv | ForEach-Object {
  $upn = $_.UserPrincipalName
  try {
    $u = Get-MgUser -UserId $upn -Property Id, UsageLocation
    if (-not $u.UsageLocation) { Update-MgUser -UserId $u.Id -UsageLocation "IN" }
    Set-MgUserLicense -UserId $u.Id -AddLicenses @(@{ SkuId = $sku.SkuId; DisabledPlans = $disabled }) -RemoveLicenses @() | Out-Null
    "OK    $upn"
  } catch { "FAIL  $upn  $($_.Exception.Message)" }
}

Prerequisites

  • Graph scope User.ReadWrite.All
  • CSV with a UserPrincipalName column

Output

One line per user with the result.

Related answers

Contributors

AuthorRole
Priyanshu UpadhyaySolution Architect, Microsoft 365 and Azure
Disclaimer. These samples are provided as is, without warranty of any kind. Read and test every script in a non-production tenant before you run it, and run reports before any command that changes or deletes data.