Office 365 Licensing with Powershell
April 2, 2012 Leave a comment
The Basics
Recently I’ve had to explore the dark art of license assignment using Powershell. It’s not particularly well documented so this might help you…
Displaying a list of the current licensing assignment is pretty straightforward. Get-MsolUser can be used to return information on an individual or a list of users.
Get-MsolUser -All run on its own will return all of the users available in the tenant along with whether or not there is a user license assigned.
To make this a bit more usable, you could pipe this output to a CSV file and work with it from there
Get-MsolUser | Export-Csv c:\path\AllUsers.CSV
If you want to filter it a bit more you can user the “TRUE” or “FALSE” options
Get-MsolUser | Where-Object {$_.isLicensed -eq “TRUE”} | Export-Csv c:\path\AllUsersWithLicenses.CSV
First Time License Assignment
The next step from here is to know what licensing SKU you have available before you can apply it. The first thing you will need to do is obtain the AccountSkuId values that have been setup for your tenant.
In my case, I have an E3 tenant which is an ENTERPRISEPACK AccountSkuId that is prefixed with the name of my tenant. You need to display your SKU:
Get-MsolAccountSku | Format-Table AccountSkuId, SkuPartNumber
If you have an E4 subscription, the AccountSkuId is ENTERPRISEPACKWITHCAL
The available service plans in each of these are
- OFFICESUBSCRIPTION (Office Pro Plus)
- MCOSTANDARD (Lync Online)
- SHAREPOINTWAC (Office Web Apps)
- SHAREPOINTENTERPRISE (Sharepoint Online)
- EXCHANGE_S_ENTERPRISE (Exchange Online)
In the Kiosk plans the AccountSkuId is DESKLESSWOFFPACK and this contains:
- SHAREPOINTWAC
- SHAREPOINTDESKLESS
- EXCHANGE_S_DESKLESS
The Exchange Online Archiving SKU contains:
- EXCHANGE_S_ARCHIVE
Doing bulk license assignments you’ll need to create a CSV file containing the UPN for each batch you want to license. I’ve names the column in my CSV “UPN”
Then you’ll need to set the licenses you would like to disable, in my example I only want to assign a license for Office Pro Plus so I need to set a variable which contains my assignment:
$Step1 = New-MsolLicenseOptions -AccountSkuId klouds:ENTERPRISEPACK -DisabledPlans MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE,EXCHANGE_S_ENTERPRISE
When assigning a license for the first time you also need to specify the country of use
Import-Csv .\Sample.CSV | foreach {set-MsolUser -UserPrincipalName $_.UPN -UsageLocation AU}
The next step is to assign the license:
Import-Csv .\Sample.CSV | foreach {Set-MsolUserLicense -UserPrincipalName $_.UPN -AddLicenses klouds:ENTERPRISEPACK -verbose -LicenseOptions $Step1}
You can check the license assignment with:
(Get-MSOLUser –UserPrincipalName “Your UPN”).Licenses[0].ServiceStatus
Modifying Subscriptions within a License
As with the first time license assignment, you will need to set a variable containing the license subscriptions you want to activate. In my example I am going to remove the Office Pro Plus subscription and activate Exchange Online:
$Step2 = New-MsolLicenseOptions -AccountSkuId klouds:ENTERPRISEPACK -DisabledPlans OFFICESUBSCRIPTION,MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE
The next step is to assign remove the Office Pro Plus subscription and assign Exchange Online
Import-Csv .\Sample.CSV | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UPN -LicenseOptions $Step2}
Again using (Get-MSOLUser –UserPrincipalName “Your UPN”).Licenses[0].ServiceStatus you can see that the change to the subscription was successful:
If you try to modify the subscription using the same commands used for first time license allocation, you will get an error stating that the license is invalid

Recent Comments