Cloud

Audit User Licenses and Services in Office 365 using PowerShell

update: 5/26/2017
BIG speed improvement thanks to NickC, who commented on my post. Also, thanks to my colleague Andy, I’ve updated the progress bar calculation so that this script can run on Windows Server 2008 R2. Thanks guys!

(You’ll need to connect to Azure AD (MSOL) prior to running this script, more info on that here)

In Office 365, licenses (also called SKUs) give users access to various Office 365 services. Each SKU defines a list of services. However, a user might not have access to all services of a given SKU. This is typical when onboarding users to Office 365 for the first time, some organizations choose to disable certain services while leaving others enabled. Office 365 PowerShell is useful to view the status of services on a given user account. This can become tricky when dealing with user accounts that have been assigned multiple SKUs.

In addition, performing a full-service audit (all users/all skus) in PowerShell can be incredibly challenging. This is primarily due to the way Azure AD (MSOL) stores the collection SKUs for a given user. The indexing is dynamic and based on the order of SKU enablement (assignment). For example, I assign User1 with E3 first and EMS second, then the index for E3 is [0] and the index for EMS is [1]. Then for User2 I assign EMS first and E3 second, the indexing for this account is the reverse and EMS is [0] and E3 is [1].

*Note that this index assignment is consistent in both PowerShell and the UI; however, if you enable/disable any services on a previously-assigned SKU using the UI, it will move that SKU to index [0]. If you use PowerShell, it will leave index number intact.

Many blogs which touch on this topic will hard-code the index to [0] in their PowerShell samples, and the assumption is your users have only one SKU or the SKU you care about is on index [0]. For example, blogs will say run the following to get service status for User1.

In my experience nearly every organization has more than one SKU. And often there is little to no consistency in the order of enablement nor consistency on which the SKUs are assigned. For example, I worked with one organization that had several thousand users and 28 different SKUs!

I wrote this script to be able to get around the dynamic index limitation, and it will get all licensed users and list their SKUs and corresponding services (and status). I hope this helps you in managing your licenses in Office 365.

(Thank you to Andy Pituch, Rianna Richardson, and Ryan Jackson for their input on this blog)

 

4 Comments

  1. john May 25, 2017
  2. NickC May 26, 2017
    • Tino Hernandez May 26, 2017
  3. LaurentF May 30, 2017

Leave a Reply