In this blog post, I will show you how to licence an Office 365 user using PowerShell and the Azure AD module.
GET License SKU
Licensing a user in Office 365 is a two-step process, first, we need to get SKU license name from our tenant using the following command. the second step is to assign the license to the user.
To connect to Office 365, Azure AD using PowerShell, visit this blog post.
Get-AzureADSubscribedSku | Select SkuPartNumber
The output of the SKU looks like the name below:
FLOW_FREE
The above SKU name os for Microsoft Flow, free license.
License user
Now that I have the SKU name of the license I would like to assign to my user, I will use the following code. In the code, I need to fill two things, the user UPN and the plan name which us the SKU I got from the above command.
$UPN="UPN@domain.local"
$Plan="FLOW_FREE"
$location = "AU"
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $Plan -eq).SkuID
$assignlic = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$assignlic.AddLicenses = $License
get-azuread
Set-AzureADUser -ObjectId $UPN -UsageLocation $location
Set-AzureADUserLicense -ObjectId $UPN -AssignedLicenses $assignlic
Get-AzureADUserLicenseDetail -objectid $UPN
To create a new user in Office 365, please visit the following post.
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.