License & Subscription Issues

Assign Microsoft 365 Licenses with Disabled Services Using PowerShell

Elise WilliamsElise Williams Nov 20, 2026 869 views

Question details

Assign Microsoft 365 licenses to users listed in a CSV file while disabling selected services.

Assign Microsoft 365 Licenses with Disabled Services Using PowerShell
Product
Microsoft 365 and Microsoft Graph PowerShell
Device & OS
not provided
Scenario
An administrator wants to process a CSV of user email addresses and assign a license without enabling certain service plans.
Observed behavior
Each listed user should receive the selected license with the specified service plans disabled.
Before you start

Prepare a CSV with an emailaddress column containing user principal names, and confirm that users have a usage location and that the tenant has available licenses. Use an account with an appropriate role, such as License Administrator, and permission to consent to the required Microsoft Graph scopes.

Solution 1Recommended

Assign licenses and disable service plans with Microsoft Graph PowerShell

Use Microsoft Graph PowerShell to apply a license and selected disabled plans to users in a CSV.

The older MSOnline commands, including New-MsolLicenseOptions and Set-MsolUserLicense, are retired. Use Microsoft Graph PowerShell instead.

The example is intended for new direct license assignments. When updating an existing assignment, include all plans that must remain disabled; otherwise, unlisted plans can be enabled. Group-based assignments should be managed through the licensing group.

1
Install and connect

Open PowerShell and run: Install-Module Microsoft.Graph -Scope CurrentUser. Then connect with: Connect-MgGraph -Scopes "LicenseAssignment.ReadWrite.All", "User.Read.All". Consent to the requested permissions if prompted.

2
Find the SKU and service plans

Run Get-MgSubscribedSku -All | Select-Object SkuPartNumber, SkuId to find the license. Then run $sku = Get-MgSubscribedSku -All | Where-Object { $_.SkuPartNumber -eq "ENTERPRISEPACK" } and $sku.ServicePlans | Select-Object ServicePlanName, ServicePlanId. Replace ENTERPRISEPACK with your tenant's SKU part number and note the exact plan names to disable.

3
Assign the license from the CSV

In PowerShell, replace the example plan names and CSV path with your own, then run: $names = @("SWAY", "YAMMER_ENTERPRISE") $plans = @($sku.ServicePlans | Where-Object { $_.ServicePlanName -in $names }) if ($plans.Count -ne $names.Count) { throw "Check the service plan names for this SKU." } $disabledIds = @($plans | ForEach-Object { $_.ServicePlanId }) Import-Csv "C:\Users\Administrator\Desktop\UserEmailAddress.csv" | ForEach-Object { Set-MgUserLicense -UserId $_.emailaddress -AddLicenses @(@{ SkuId = $sku.SkuId; DisabledPlans = $disabledIds }) -RemoveLicenses @() }

4
Verify an assignment

Run Get-MgUserLicenseDetail -UserId "user@example.com" | Select-Object SkuPartNumber -ExpandProperty ServicePlans. Check that the intended plans show a disabled provisioning status, and review any errors returned during the CSV loop.

Assign licenses and disable service plans with Microsoft Graph PowerShell
Check plan names before running: Service plan names vary by SKU. Use the names returned for your subscribed SKU rather than assuming that a product name, such as Teams or Yammer, is the plan name.
Free Microsoft Office alternative

Use WPS Office as an alternative for everyday office work

WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easier to move everyday documents between suites. It does not manage Microsoft 365 licenses or service plans.

Free, lightweight tools for everyday office workCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for a smoother transition from Microsoft OfficeOpen and edit CSV files used to prepare user lists
microsoft office alternative - wps office

Frequently Asked Questions

Can I still use New-MsolLicenseOptions to disable services?

The MSOnline module is retired. Use Microsoft Graph PowerShell and pass service plan IDs in the DisabledPlans property of Set-MgUserLicense instead.

How do I find the exact service plan name for Teams or Yammer?

Select the subscribed SKU with Get-MgSubscribedSku, then inspect its ServicePlans property. Use the returned ServicePlanName and ServicePlanId values; names can differ by SKU.

What column should the CSV contain?

The example uses an emailaddress column containing each user's principal name. If your CSV uses another header, change $_.emailaddress in the Import-Csv loop to match it.

Can I use this script to change licenses assigned through a group?

Manage group-based license settings through the group rather than using the example for a direct user assignment. Check the user's license assignment source in the Microsoft 365 admin center before making changes.

Why might a license assignment fail?

Check that the account has an appropriate administrator role and Graph permissions, that the SKU has available licenses, and that the user has a usage location. Also verify the user principal name and service plan IDs.