Skip to content

How to bulk assign Office 365 licenses to ALL users

March 13, 2013

You can bulk assign licenses to all users in your MSOL subscription if needed from a single script. But are you sure you’d want to? Would you really want to indiscriminately license every MSOL user with the same SKU and usage location? You do? No you don’t! I’d strongly recommend bulk assigning licenses from CSV file instead, but if you’re happy to proceed then use the following procedure:

1. Log on to a machine that has ‘Microsoft Online Services Module for Windows PowerShell’ installed. You can install this on your own workstation but it should also be installed on your ADFS Servers.

2. Enter the following command and specify credentials for an account that has administrator permissions to your MSOL subscription (such as admin@{tenant_id}.onmicrosoft.com):

$cred = Get-Credential

3. Enter the following command to connect to Microsoft Online Services:

Connect-MsolService -Credential $cred

4. Enter the following command to retrieve your organization’s license details:

Get-MsolAccountSku |ft AccountSkuId

5. Note the AccountSkuId value returned and use in the next step

6. Run the following command, editing the first two lines as necessary:

$AccountSkuId = "{AccountSkuId}"
$UsageLocation = "{UsageLocation}"
$Users | Get-MsolUser -resultsize unlimited
$Users | ForEach-Object {
Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation
Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId
}

For example:

$AccountSkuId = "ExitCodeZero:STANDARDWOFFPACK"
$UsageLocation = "GB"
$Users | Get-MsolUser -resultsize unlimited
$Users | ForEach-Object {
Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation
Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId
}

There’s lots of pretty screenshots, which I won’t duplicate here, in my previous post How to bulk assign Office 365 licenses from CSV file.

Please note that unlike the procedure to assign licenses from CSV file, there’s no nice way of testing this on pilot accounts. Follow this procedure entirely at your own risk.

Advertisements
2 Comments
  1. Moaaz permalink

    Thank you for the helpful post,

    I’m facing the following error:
    ———————————————————————————————————–
    Set-MsolUserLicense : Unable to assign this license because it is invalid. Use
    the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
    At line:3 char:1
    + Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses
    $Accoun …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
    + CategoryInfo : OperationStopped: (:) [Set-MsolUserLicense], Mic
    rosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.Inval
    idUserLicenseException,Microsoft.Online.Administration.Automation.SetUserL
    icense
    ————————————————————————————————————-

    I used the license returned by Get-MsolAccountSku |ft AccountSkuId

    Any idea?

    moaaz

    • Hi Moaaz

      I’ve just copied and pasted the script with an active tenant and it works fine. The first line should follow the exact syntax below and include the tenant name:

      $AccountSkuId = “ExitCodeZero:STANDARDWOFFPACK”

      It makes no difference whether or not you include spaces either side of the equals sign. You must enclose in quotes. Try typing the quotes (Shift-2) rather than copying and pasting to ensure you enter valid characters. Copy and paste the script into Notepad first, rather than directly into PowerShell.

      The $AccountSkuId variable in the last line must match the variable defined at the start of the first line exactly.

      Hope this helps, Dave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: