Assign licenses for specific services in Office 365 using PowerShell

For the first post of the year, we’ll learn how to assign only specific services (ServicePlan) to users in Office 365, and for efficiency as always, we’ll use PowerShell to do so! 🙂

You may have some O365 users in your organisation where, you only wish to give them access to Exchange Online, or SharePoint Online, and so on.
Be aware though, it’s not because you assign only some services that the subscription will be cheaper!

Now, with that being said, let’s get started.


Minimum requirements:

  • PowerShell modules to connect to Office 365
  • Permissions to run PowerShell scripts
  • CSV file containing the users to license


Retrieve Subscription(s) and Services

As always, first thing to do is to connect to Office 365 (Refer to the official documentation if you need: Connect to Office 365 PowerShell)


Connect to O365

Now that we are connected, let’s retrieve our subscription(s)


Here we can see all our subscription(s) – I have 3 in total


Subscription(s) in the tenant

Next step will be to get the services for a particular subscription.
In this case, we’ll choose the “DEVELOPERPACK” one.

The following PowerShell line will give us what we need.

Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'DEVELOPERPACK'} | Foreach-Object {$_.ServiceStatus}

Services under the DeveloperPack subscription

Those “ServicePlan” reflect each service available under your subscription.


  • EXCHANGE_S_ENTERPRISE = Exchange Online

And so on…


Create a variable for the services to assign

The logic in here, is kind of backwards.
Let me explain: if you wish to assign only an Exchange Online plan to users, then you need to disable the other plans.

There is a parameter called -LicenseOptions in PowerShell when assigning licenses, and that’s what we’ll use later on.

Let’s see that in action 🙂

In this scenario, we’ll assign only Exchange Online, Skype for Business, and Sway to the user(s) – randomly picked!
Meaning we’ll disable the other plans not needed.

My variable is called $MyServicePlans and uses the -DisabledPlans parameter to exclude what we don’t want the user(s) to get.


Change the <tenantName> with yours
No need to include the INTUNE_O365 in the excluded plans


Assign the licenses to users

Now we have saved the chosen plans in a variable ($MyServicePlans), let’s assign the licenses to the users.

The PowerShell cmdlet will look like this:

Set-MsolUserLicense -UserPrincipalName <userPrincipalName> -AddLicenses <tenantName:DEVELOPERPACK> -LicenseOptions $MyServicePlans


HOWEVER, PowerShell is used to automate, right? Don’t repeat a task manually several times??
So let’s make this a script to assign licenses to multiple users!

Full Script

#Define the plans to assign

#Store the DeveloperPack Account Sku into a variable
$DevAcctSku = Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'DEVELOPERPACK'}

#Import users from CSV file
$MyUsers = Import-Csv -Path C:\Users\$env:USERNAME\Desktop\UsersToLicense.csv

#Assign licenses to users
foreach($user in $MyUsers){
    Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -AddLicenses $DevAcctSku.AccountSkuId -LicenseOptions $MyServicePlans



The users in O365 need to have the “UsageLocation” filled before having a license assigned to them. Otherwise you will get an error “Set-MsolUserLicence: You must provide a required property: Parameter Name: UsageLocation

To get all your users missing a location, type Get-MsolUser | where-object {$_.UsageLocation -eq $null}


Check licenses are assigned

Log into your tenant, and there we have it 🙂


Licenses assigned as needed!




One Response to “Assign licenses for specific services in Office 365 using PowerShell

  • I know how to do that part. But how do I assign a specific service to all of my users that may already have different services assigned to each of them? MS doesn’t provide a way from what I can find. This script assumes all users would have the same disabled services, which may not be the case.

%d bloggers like this: