Thursday, December 7, 2017

Add O365 License to users in bulk

We are moving to O365 and I needed a way to add our O365 licenses in bulk. To do this I used PowerShell.

First you need to install the AzureAD V2 PowerShell. This is very easy if you have Windows 10. You will do this:

Install-Module AzureAD

Once you install the module you will need to connect to your account:


It will prompt you for your O365 global admin credentials. Once you are connected you can see what your License SKU is by doing this:

Get-AzureADSubscribedSku | Select Sku*,*Units

The one we have it called ENTERPRISEPACK. You will need the SkuID. From this point you can put in the code below. I used a CSV file with a header of UserPrincipalName (UPN) and then below that the users. The UPN looks like an email address.

$file = import-csv test.csv

foreach ($user in $file){

$upn = $user.UserPrincipalName

$user2 = Get-AzureADUser -SearchString $upn

Set-AzureADUser -ObjectId $user2.ObjectId -UsageLocation US

$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense

$License.SkuId = "6fd2c87f-b296-42f0-b197-1e91e994b900"

$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

$LicensesToAssign.AddLicenses = $License

Set-AzureADUserLicense -ObjectId $user2.ObjectId -AssignedLicenses $LicensesToAssign


This went through all my users in the CSV file and assigned the E3 license to their account.

No comments:

Post a Comment

User unable to login to RDP Farm after you re-enable them?

We had a strange issue. We had a user leave and since we knew when she was leaving i set the account to expire at a certain date. A couple d...