Assign Office 365 License via PowerShell

You can assign a license to a user using the Microsoft Portal, just select the user and in the Action Pane select USERS –> Active Users. Depending on the licenses you got available you can assign it (in this example a Visio pro Office) and set the user’s location (in this example Switzerland):

This step is comfortable if you want to assign only one user license, if you want to assign a license to a group of users you can also user PowerShell (with the Windows Azure Active Directory module) to accomplish this. More Details you can find here how you can install this module.

To retrieve licensing information you have to setup a connection with Microsoft Online and use the Get-MsolAccountSku command:

$Cred = Get-Credential
Connect-MSOLService –Credential $Cred
Get-MsolAccountSku

So in this demo environment we have 200 licenses available for this organization.2

The license can be assigned to a user using the SetMsolUserLicense. You have to set the User Location (as can be seen in the GUI). When the User Location is set you can assign a license:3

When you check the Microsoft Portal you’ll see the license is assigned:4

If you have more users you can export the user principal names into an CSV file and use the following script:

$Cred = Get-Credential
Connect-MSOLService -Credential $Cred
Get-MsolAccountSku

$AccountSkuId = “TENANTNAME:VISIOCLIENT”
$UsageLocation = “CH”
$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId

$Users = Import-Csv c:\Users.csv

$Users | ForEach-Object {

Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation

Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId -LicenseOptions $LicenseOptions
}

In case of ENTERPRISEPACK Plan where the license model is more complex, you can disable some services with DisabledPlans switch.

For example if you want to activate Exchange Online and Lync Online services from your Office 365 E3 Plan to your customer you need to use the use following command:

$OnlyLyncExch = RMS_S_ENTERPRISE,OFFICESUBSCRIPTION,SHAREPOINTWAC,SHAREPOINTENTERPRISE
$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans $OnlyLyncExch

It’s much useful, isn’t it! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *