Office 365 – User Licensing basics using PowerShell

I’ve been doing quite a bit of work around Office 365 lately, and have been getting a number of question’s around licensing of users.

In this post ill cover the most basic commands needed for managing users. Sometime i’ll hopefully find the time to write a post covering some of the more detailed options available when managing licenses.

Salamander Active Directory
Firstly, I should say that Salamander Active Directory can now handle the Licensing needs for most schools.

It can be used to manage the licenses for existing users as well as new starters and leavers.

Connecting to Office 365
The first step is to connect to Office 365. If your not familar with this, have a look at this post: http://blog.atkinson-it.com/?p=109

List all the License Plans
Licenses are packaged into plans. When you are working in Office 365 online, you’ll see the ‘display’ name for these, but when working in Powershell you need to know their ‘real’ name, or AccountSKU.

You can very quickly get a list of the AccountSKU’s in your Tenancy using:

#Basic command
Get-MsolAccountSku

#More detailed information
Get-MsolAccountSku | Format-Table AccountSkuId, SkuPartNumber, ActiveUnits, ConsumedUnits

Service Plans
Once you’ve established the names of the Plans, it is often useful to look at the service plans inside those. Often it may be that a user doesn’t need to have all the available service plans when configuring licenses.

In my Office 365 setup, i have a number of License plans, including:

SalamanderSoft:ENTERPRISEPACK

In the Office 365 Admin Centre this shows as:

EnterprisePack

In Powershell, you can get a list of these service plans using:

$ServicePlans = Get-MsolAccountSku | Where {$_.AccountSkuId -eq "SalamanderSoft:ENTERPRISEPACK"}
$ServicePlans.ServiceStatus

This will list the available service plans in the Pack selected.

In my tenancy these are:

serviceplan

Seeing the licenses for a single user
Sometimes its useful to view the license status for an exsiting user. This is easily done using the following:

$user = "testUser@salamandersoft.co.uk"
(Get-MSOLUser –UserPrincipalName $user).Licenses[0].ServiceStatus

 

Add a License for a single user
Adding a license with a full pack is very straight forward and can be done with a single command.

Here i am using the variable $user to define the user in question.
You could just add the Full UPN of the user instead.

 

$user = "myuser@mydomain.com"
Set-MsolUserLicense -UserPrincipalName $user -AddLicenses SalamanderSoft:ENTERPRISEPACK 

Adding a License using License Options
Where a user doesn’t need to get the full pack, you can add specific set of plans, by using Licence Options.

In this example, i have used the license options parameter to add the license, with some of the options disabled.

#Set License Options (to disable various plans)
$MyLicenseOptions = New-MsolLicenseOptions -AccountSkuId SalamanderSoft:ENTERPRISEPACK -DisabledPlans OFFICESUBSCRIPTION, RMS_S_ENTERPRISE,MCOSTANDARD

#Set Licenses using the options above
Set-MsolUserLicense -UserPrincipalName $user -AddLicenses SalamanderSoft:ENTERPRISEPACK -LicenseOptions $MyLicenseOptions

This will result in the Office 365 Admin page looking like this:

EnterprisePack

Removing a License for a single user
We can also remove the license for a single user with a single command.

Set-MsolUserLicense -UserPrincipalName $user -RemoveLicenses SalamanderSoft:ENTERPRISEPACK

Office 365 – Changing a Username

Recently, i’ve been doing quite a bit of work with clients who have needed to change their usernames in Office 365 for one reason or another and have having difficulty.

In some cases they have managed to update it through the portal, but more often than not, its not quite worked properly and they have needed to change the User Principal Name manually using Powershell.

The good news is that its really straightforward to do. Infact, it’ll probably take you longer to get connected to Office 365 than it will to change the User Principal Name for a user.

Changing a single users User Principal Name
Once your connected (see my blog post on connecting to Office 365) you can simply run the powershell:

#Changing the UserPrincipalName for a single user
Set-MsolUserPrincipalName -UserPrincipalName "myOldUpn@mydomain.co.uk" -NewUserPrincipalName "myNewUpn@mydomain.co.uk"

This will do simply that, load the object for the user and change their Upn.

If you wanted to do that with variables to make things a little tidier you can:

#Chaning the UserPrincipalName for a single user - using variables
$oldUPN = "myOldUpn@mydomain.co.uk"
$newUPN = "myNewUpn@mydomain.co.uk"
Set-MsolUserPrincipalName -UserPrincipalName $oldUPN -NewUserPrincipalName $newUPN

Changing more than one
This works really nicely, but last week I had a customer who wanted to change around 30 for various reasons, so I had them make a CSV file to hold the details in 2 columns:

upnchanges.csv
oldUpn,newUpn
oldUpn@domain.com,newUpn@domain.com
oldUpn2@domain.com,newUpn@domain.com

Once they’d generated this file, I simply used the below to change the User Principal Name for everyone in the CSV.

#Using a CSV File to change the UPN's
$path = "c:\pathtomycsv\upnChanges.csv"
Import-csv -path $path | 
foreach-object `
{ 
  Set-MsolUserPrincipalName -UserPrincipalName $_.oldUPN -NewUserPrincipalName $_.newUPN
}