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.
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;
This can be safely ignored.Hope this helps.