How to assign license to an Office 365 user using powershell

How to assign license to an Office 365 user using powershell

 

In this blog post, I’ll show you How to assign license to an Office 365 user using powershell via Microsoft Azure Active Directory Module.

Using the Azure Active Directory PowerShell Module (AzureAD) helps to automate the streamlined the entire Office 365 administration and rollup process.

When using the Portal, the basic tasks like assigning licenses, Reset password and Creating new users can take a few minutes.

But when using the AzureAD module these tasks can take seconds to complete and when scaling the script we can easily reapply to multiple users when using .CSV.

My recommendation to every Office 365 Administrator Is to keep a script library for Office 365 management.

The requirements for this article are:

  • PowerShell 5.0 and above – Need for the AzureAD PowerShell module
  • User account with administrative permissions to create new users In Office 365
  • The AzureAD Powershell module

For a quick Install of the module, Open PowerShell 5.0 and above and type:

Install-module AzureAD
 

The first step, In assigning license using AzureAD Is to get to get the License SKUID of the subscription and the best way to do it Is to look up An existing activated user detail using AzureAD

 

Get-AzureADUser -ObjectId [email protected]

How to assign license to an Office 365 user using powershell
How to assign license to an Office 365 user using powershell

Below, I’ll get the details using the code below of an activated user.

Get-AzureADUser -ObjectId [email protected] | select AssignedLicenses |fl

Note: run the cmdlet and copy the Skuid as shown below.

How to assign license to an Office 365 user using powershell
How to assign license to an Office 365 user using powershell

Next, paste the Skuid to code below.

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

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

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

$licenses.AddLicenses = $license

This Is an optional cmdlet If you get an error about the Usage Location:

Set-AzureADUser -ObjectId "[email protected]" -UsageLocation "AU"

The cmdlet below will apply license details to the user and assign a license to it.

Set-AzureADUserLicense -ObjectId "[email protected]" -AssignedLicenses $licenses

If I check the user details I will the assigned license

get-AzureADUser -ObjectId "[email protected]" | fl

Search








Bitnami