Adding Office 365 License via PowerShell

Assigning Office 365 license via PowerShell is the need of the hour if the tenant doesn’t have a p1 license and you got to apply them manually.
the only easy way is to use PowerShell for bulk license assignment. Also, it’s useful to upgrade or renew different licensing.

Connect-AzureAD

if you don’t have the module

Install-Module -Name AzureAD
Get-AzureADUser -ObjectID username@azure365pro.com | Select DisplayName, UsageLocation

Got the usage location as US

Import-Csv .\assignexchstandard.csv | ForEach-Object {Set-AzureADUser -ObjectId $_.upn -UsageLocation "US"}

use the below command to Cross-checking on applied values – or use GUI

Import-Csv .\assignexchstandard.csv | ForEach-Object {Get-AzureADUser -ObjectId $_.upn | FT UsageLocation }

Now usage location is updated on the required accounts. as it’s mandatory before assigning a license via PowerShell. in my case, I don’t have a p1 license in this tenant that’s the reason I got to do this via PowerShell otherwise I would use dynamic licensing

Get-AzureADSubscribedSku | Select SkuPartNumber

In my case, I need to assign ExchangeStandard

$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value EXCHANGESTANDARD -EQ).SkuID
$License.SkuId
4b9405b0-7788-4568-add1-99614e613b69
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
$LicensesToAssign | FL

AddLicenses : {class AssignedLicense {
DisabledPlans:
SkuId: 4b9405b0-7788-4568-add1-99614e613b69
}
}
RemoveLicenses :

once you have a proper value assigned on this variable $LicensesToAssign
you can use import-csv to assign all users.


Import-Csv .\assignexchstandard.csv | ForEach-Object {Set-AzureADUserLicense -ObjectId $_.upn -AssignedLicenses $LicensesToAssign}

Now you can see licenses got assigned successfully.

 

About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Office Server and Services MVP , Publisher of Azure365pro.com. Specialized in Office365 / Microsoft Exchange / Virtualization , Sathesh is an Messaging Expert supporting/Designing/Deploying many medium size businesses to large enterprises when it comes to Corporate messaging and Virtualization Infrastructure

Check Also

az Git Terraform configs to work behind Proxy

Let’s see how to configure proxy for az Git and Terraform behind an authenticated proxy …

Leave a Reply

Your email address will not be published.