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
CSV
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.
user,displayname,upn,nickname,password NTTest01,NT Test 01,[email protected] NTTest02,NT Test 02,[email protected]
To find out how to find the license SKU using Azure AD PowerShell please visit this blog post on this topic.
Script
The following script takes the CSV file and licenses the two users with the Microsoft Flow license.
$planName="FLOW_FREE" $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 }