Office 365 – Adding Users and Assigning Licences With PowerShell

Creating an Office 365 Tennant is a bit pointless if no one can use the services. In this post, I will detail the process for adding users and licencing users with PowerShell. The best part about this process is that it can be used for a single user, or a list of users.

Purchasing licences

If you haven’t already, head over the the Office 365 Admin Center and purchase a subscription through the Billing > Subscriptions section.

Connect to Office 365

To connect to Office 365 with PowerShell you will need to install the following

  1. Microsoft Online Services Sign-In Assistant
  2. Windows Azure Active Directory Module

Once installed, you will have access to new PowerShell cmdlets. You can see the full list by running

Get-Command -Module MSOnline

Now you can run

Connect-MsolServer -credential (Get-Credential)

You will get a prompt for your username and password, enter these and you’ll be returned to the PowerShell prompt.

Create a CSV file

To import multiple users, the simplest method is to use a CSV file with the following headings:
DisplayName,FirstName,LastName,UserName,License,Location

Fill in the appropriate details. The location will be the two-letter country code for the user e.g. AU. To see the available licenses run

Get-MsolAccountSKU

msolaccountsku

The number under ActiveUnits is the number of available licences of that type. ENTERPRISEPACK is an E3 licence. In the Licence collumn of the CSV file, enter in the full AccountSkuId required for the User. e.g. itcloudpro:ENTERPRISEPACK

Creating the users

This one is pretty simple. We just need to import the CSV file, and loop through it for each user.

$csv = Import-CSV C:\users.csv
$csv | foreach{New-MsolUser -UserPrincipalName $_.UserName -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -LicenseAssignment $_.License -UsageLocation $_.Location

If there are no errors, you will get back a list of users, their initial password and their license status.

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 )

w

Connecting to %s