Enabling Users for Office 365 Licensing Made Easy

When transitioning to the cloud, some of Microsoft’s new PowerShell commands can be hard to find solid answers on and are completely different in some cases from what most Exchange administrators are used to using.  The Set-Msoluser cmdlet for instance is not something that you had ever seen in Exchange 2007 or 2010.  I’m often asked the easiest method for giving a user a license without manually clicking through the Portal for 1000+ users.  Today I’ll share a simple way to get this done and save time during a migration.

These new PowerShell cmdlets make assigning licenses to users very simple and much faster than using the Online Services portal to manually assign licenses. This post will walk you through how to make a basic PowerShell script that reads a CSV file to activate and assign licenses to users in your target Office 365 environment.

Step 1 – Determine the license types you have.

Before we configure the script we’ll need to know what the license types are in order to include them in our script. 

Connect to the Msol service using Connect-MsolService and enter in valid administrator credentials.

Run the following PowerShell command to determine the license types:

Get-MsolAccountSku | Format-Table AccountSkuId, SkuPartNumber

The output should look something like this:

AccountSkuId SkuPartNumber
------------ -------------

I’ve removed the company name before the : but it should be similar. For this example’s purposes let’s call the licenses TEST:STANDARDPACK and TEST:ENTERPRISEPACK.

Step 2 – Configure your CSV input file

Now we can start to create the input file.  We’ll need a bit more information about your users but generally we’ll set the CSV up with 3 columns:  Username, LicenseType, Location.  The Username column will be the UPN or online login name of the user (these should match).  The LicenseType will be based upon the outputs we received from step 1.  The Location is where the location needs to be set for each user, such as >US for United States, IN for India, MX for Mexico, and so on.  It should look something like the following.

username licensetype location
user01@test.onmicrosoft.com TEST:STANDARD us
user02@test.onmicrosoft.com TEST:ENTERPRISE in
user03@test.onmicrosoft.com TEST:ENTERPRISE mx
user04@test.onmicrosoft.com TEST:STANDARD us

Save the inputfile in ‘msol_activate.csv’. Now we can go on the script.

Step 3 – Configure the Script

Now that our input file has been setup we can write the script accordingly.  Let’s open a notepad file.

We’ll need to define our list and just refer to it as $List and use Import-CSV to read the CSV file:

$List = Import-CSV “msol_activate.csv"

No we’ll start the loop using foreach and call out $User as each line of the $List

foreach ($User in $List)

In the first line we’ll set the UsageLocation since it is required before setting the license.  The name of the columns from our CSV file will be added to $User so the script can grab them specifically.

Set-MsolUser -UserPrincipalName $User.Username -UsageLocation $User.Location

Now we’ll add the license type:

Set-MsolUserLicense –userprincipalname $User.Username –addlicenses $User.LicenseType

And lastly we’ll set a default password and force the user to change that password the first time they log in, then close the loop:

Set-MsolUserPassword -UserPrincipalName $User.Username -ForceChangePassword $true -NewPassword "Office365Rules"

You could also add a column to your CSV file named Password and have the –NewPassword be $User.Password.

Put it all together and the script looks like this:

$List = import-csv  “msol_activate.csv"
foreach ($User in $List)
    Set-MsolUser -UserPrincipalName $User.Username -UsageLocation $User.Location
    Set-MsolUserLicense –UserPrincipalName $User.Username –addlicenses $User.LicenseType
    Set-MsolUserPassword -UserPrincipalName $User.Username -ForceChangePassword $true -NewPassword "Office365Rules"


So now we have successfully determined our license types, take our user data and put it into an input file and created a script that easily gives our users a license and a temporary password.  This script will help get your users to the cloud faster and assigned licenses much faster than manually using the portal.


Peter Gleek
BA Advanced Infrastructure Principal Consultant