Office 365 – Bulk Assign Licences

Office 365 logo

Office 365 logo

 

So, in Office 365, how do you bulk assign licences to users.

I had a search around and could only really find examples using CSV file imports, what I wanted to do was pull the information in directly from Active Directory.

Whilst looking around I found the Get-ADUser cmdlet available through RSAT.

This cmdlet pulls out information from AD relating to accounts etc.

Using the -Filter command you can limit this to a specific OU.

We currently use ADFS to authenticate our users for SSO and this is all installed on it’s own server.

So on that server I added the RSAT AD DS and AD LDS Tools Feature.

Office 365 - Install RSAT Feature

Office 365 – Install RSAT Feature

The next thing needed was the Account SKU ID for the licences I wanted to assign to my users.

Using Microsoft Online Services Module for Windows PowerShell;

Connect-Msolservice

Supply Office 365 Administrator credentials.

Get-MsolAccountSku

Now we need to add the Active Directory modules;

Import-module ActiveDirectory

 Now, to make thing a bit easier we assign some variables;

$AccountSkuId = “SiteName:SKUNAME”

(This was obtained earlier from the Get-MsolAccountSku command)

Set a Location;

$UsageLocation = “GB”

Set Licence Options;

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId

Get the Users;

$Users = Get-ADUser -Filter * -SearchBase “OU=someOU,OU=SomeOtherOU,DC=DOMAIN,DC=LOCAL”

Now we assign the licences;

$Users | ForEach-Object {

Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation

Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId -LicenseOptions $LicenseOptions

}

 Obviously this could all be added to a single script and if the Administrator credentials were supplied, this could then be ran as a scheduled task.

Any users that already have a licence installed will get an error;

Office 365 - PS Error

Office 365 – PS Error

This can be safely ignored.Hope this helps.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post Navigation