How To License Multiple Office 365 Users With PowerShell

In this blog post, I will show you how I license multiple Office 365 users with PowerShell and a CSV file without using the Office 365 admin portal.

Azure PowerShell Module

To complete this task, I will use the Azure AD PowerShell module that is based on PowerShell 5.1 and can only work from a Windows machine.

Connect and Install Azure AD PowerShell module


In this use case, I have the following CSV file that has two users and for this demo, I will license my two users with MS Flow license.

NTTest01,NT Test 01,nttest01@domain.local
NTTest02,NT Test 02,nttest02@domain.local

To find out how to find the license SKU using Azure AD PowerShell please visit this blog post on this topic.


The following script takes the CSV file and licenses the two users with the Microsoft Flow license.

$location = "AU"
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $planName -EQ).SkuID
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License

$users = import-csv 0365_users.csv

foreach ($user in $users)
Set-AzureADUser -ObjectId $user.upn -UsageLocation $location
Set-AzureADUserLicense -ObjectId $user.upn -AssignedLicenses $LicensesToAssign
Get-AzureADUserLicenseDetail -objectid $user.upn 

Leave a Reply

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