Assign and Remove Microsoft 365 Licenses in Bulk with PowerShell
Question details
The user needs to assign and remove Microsoft 365 licenses in bulk and resolve invalid license options errors.

- Product
- Microsoft 365 and Microsoft Graph PowerShell
- Device & OS
- not provided
- Scenario
- An administrator manages licenses for multiple users from a CSV file or group and needs to validate the SKU, service plans, and usage locations.
- Observed behavior
- Bulk licensing can fail with an invalid license options error when the SKU, disabled plans, user location, or CSV data is incorrect.
Use an administrator account with appropriate licensing permissions and check that the target subscription has enough available licenses. Prepare a CSV with UPN and UsageLocation columns, and test changes on a small group before processing the full list.
Assign licenses from a validated CSV with Microsoft Graph PowerShell
Use this method to set user locations, assign a selected SKU, and record successes and failures.
The older MSOnline commands, including Get-MsolAccountSku and Get-MsolUser, are retired. Use Microsoft Graph PowerShell for current administration.
A disabled service plan must belong to the selected SKU, and plan dependencies can affect whether an assignment succeeds.
In PowerShell, install the Microsoft.Graph module if needed with Install-Module Microsoft.Graph -Scope CurrentUser. Then run Connect-MgGraph -Scopes 'User.ReadWrite.All','Organization.Read.All','LicenseAssignment.ReadWrite.All' and sign in with an appropriately privileged administrator account. Consent may be required.
Run Get-MgSubscribedSku | Select-Object SkuPartNumber,SkuId,ConsumedUnits,PrepaidUnits. Select the intended SKU with $sku = @(Get-MgSubscribedSku | Where-Object SkuPartNumber -eq 'YOUR_SKU_PART_NUMBER'); if ($sku.Count -ne 1) { throw 'Select exactly one SKU' }; $sku = $sku[0]. Inspect its plans with $sku.ServicePlans | Select-Object ServicePlanName,ServicePlanId.
Create users.csv with UPN as the first column and UsageLocation as the second, using valid two-letter country codes such as US. Check for blank or duplicate UPNs and confirm that each user and location is correct. Set $disabled = @() to enable all plans; if disabling plans, populate it with verified ServicePlanId values from $sku.ServicePlans.
Run: $results = foreach ($row in (Import-Csv .\users.csv)) { try { if (-not $row.UPN -or -not $row.UsageLocation) { throw 'UPN or UsageLocation is missing' }; Update-MgUser -UserId $row.UPN -UsageLocation $row.UsageLocation -ErrorAction Stop; Set-MgUserLicense -UserId $row.UPN -AddLicenses @(@{SkuId=$sku.SkuId; DisabledPlans=$disabled}) -RemoveLicenses @() -ErrorAction Stop | Out-Null; [pscustomobject]@{UPN=$row.UPN; Status='Success'; Error=''} } catch { [pscustomobject]@{UPN=$row.UPN; Status='Failed'; Error=$_.Exception.Message} } }; $results | Export-Csv .\license-results.csv -NoTypeInformation. Review license-results.csv before expanding the batch.

Remove a specific license from users in a CSV
Use this method after validating the target users and SKU when you need to remove directly assigned licenses.
Review bulk licensing CSV files with WPS Office
WPS Office is a free, lightweight alternative for reviewing licensing spreadsheets and CSV files. Its familiar interface and Microsoft Office format support make it easy to move existing files between suites. Microsoft 365 license changes still require Microsoft's administration tools.

Frequently Asked Questions
Why do I get an invalid license options error?
Check the selected SKU and inspect its ServicePlans with Get-MgSubscribedSku. Every disabled plan ID must belong to that SKU, and plan dependencies must be satisfied. Also verify the user's usage location and CSV values.
What columns should my licensing CSV contain?
For the assignment example, use UPN and UsageLocation headers, with one user per row and a valid two-letter country code. If using the older Office 365 Licensing Tool, put UPN in the first column.
Can I remove a license that a user inherited from a group?
Manage an inherited license through the group's licensing settings. Check the user's assignment in the Microsoft 365 admin center under Users > Active users > Licenses and apps before making changes.
Can I use Get-MsolAccountSku for a new licensing script?
The MSOnline module is retired. Use Get-MgSubscribedSku to inspect subscriptions and Set-MgUserLicense to change assignments with Microsoft Graph PowerShell.




