PowerShell: Assign Licenses

We frequently assign licenses to a bulk of users when customers migrate to Office 365, and ofcourse we use PowerShell 🙂

Prereqs: User must have defined a Location/Country.

First you’ll need a source with users to assign a license type, and we have used two ways:

Example1: Import-CSV File (See Export-CSV File)
Example2: Get-MsolUser -DomainName yourdomain.com

Second we need to find the name of your Office 365 license.

This command will show all of your license types.
Get-MsolAccountSku

But the name is to long, so we add a Select AccountSkuId to only get the name.
Get-MsolAccountSku | Select AccountSkuId

To add a license we leverage Set-MsolUserLicenses command:
Set-MsolUSerLicenses -UserPrincipalName myuser@mydomain.com -AddLicenses “AccountSkuId”

But that will only give one user a new license, so we combine this with the CSV-file:
Import-CSV -Path C:File.csv | ForEach-Object | Set-MsolUSerLicenses -AddLicenses “AccountSkuId”
or
Get-MsolUser -DomainName yourdomain.com | ForEach-Object | Set-MsolUSerLicenses -AddLicenses “AccountSkuId”


Leave a Reply

Ehlo!

I am Roy Apalnes, a Microsoft Cloud Evangelist working av Sopra Steria. Main focus in Microsoft Security and Endpoint Management, with a bigger picture in mind.

Featured Posts