[Function] Export Report of Unused Office 365 Licenses Across Multiple Tenants or a Single Tenant Using Friendly License Names

[Function] Export Report of Unused Office 365 Licenses Across Multiple Tenants or a Single Tenant Using Friendly License Names

Even if a license is not assigned to an Exchange Online object does not mean it’s not being charged back to the tenant. If you work for a MSP or IT Consultant you may want to audit your clients Office 365 tenant for any licenses that are not assigned so they are not paying for licenses that they do not need.

While looking up ways to accomplish this task I came across this script from GCITS. If you have never read any of GCITS’s knowledge-base write ups I recommend you start following their blog posts as they have some of the best write ups, especially for MSP’s, and IT Consultants. The problem with the script is that it exported the unused license count for all licenses including licenses that had zero unused licenses. It also exported the license SKU instead of converting it to a friendly name. If you have to give this report to someone who hasn’t memorized all the SKU’s, and what license it correlates to, then the report isn’t as helpful as it could be. By converting it to it’s proper friendly name you can easily remove the licenses since Microsoft and other resellers like Sherweb also don’t display licenses in the portal by SKU.

I also wanted to make the script into a PowerShell Function instead of a flat script. This would allow me to save the function into my PowerShell profile, and also give it to others without having to modify anything in the script itself. The CSV output path would be a parameter instead of a set item in the script you would have to modify. It would also allow you to run it across a single tenant or all tenants using a switch parameter.

Using delegated administration in Office 365 you can quickly manage multiple tenants while only needing one login. This script will allow you to use delegated administration to get an unused license report across all your tenants or just a single tenant.

 

What You Need:

  • If you are running this across multiple tenants make sure you are a delegated admin on the tenants
  • PowerShell

The Script

If you just want to download and run the script without reading the inner-workings of it then feel free to scroll to the bottom of the page and copy and save the script.

Help

The Function we are creating is Get-UnusedLicenseReport. By saving this into my PowerShell profile I can call the function when launch PowerShell. The Function also comes with detailed Help.

Detailed Help for Get-UnusedLicenseReport

Parameters

The script has 3 parameters with only 1 being mandatory.

CSVPath: The path where the csv report will be saved to; required.

Username: The Office 365 username; not required.

TenantReport: Switch parameter, Include this if you want to run against all tenants instead of a single tenant; not required.

 

Display

The shell will display the licenses for each tenant and the unused license count. If it’s green then there are 0 unused licenses and there is no more steps involved. If there are more than 0 unused licenses it will be displayed in magenta and will be exported to the result csv file. If the hash table cannot look up a SKU to a friendly name it will display red and export the SKU name to the result csv file.

The Shell when ran against a single tenant

 

The Shell when running against multiple tenants

CSV Report

The CSV report will include the company name, friendly license name, active units, warning units, consumed units, and unused units.

The csv report when ran against multiple tenants

Script

 

My name is Bradley Wyatt; I am currently a Technology Specialist at Porcaro Stolarek Mete Partners which is headquartered in Chicago, Illinois. At PSM we provide solutions which are custom designed around the specific needs of each client.

4 thoughts on “[Function] Export Report of Unused Office 365 Licenses Across Multiple Tenants or a Single Tenant Using Friendly License Names

  1. Hi Darren –
    Any suggestions? I looked into it but the SKU doesnt always say free or trial in it, I was thinking of excluding AccountSkus with greater than 99999 licenses

  2. Great script and yes those GCITS guys are amazing. Some addtional SKUs for your script below

    “WINDOWS_STORE” = “Windows Store for Business”
    “MCOEV” = “Microsoft Phone System”
    “VIDEO_INTEROP” = “Polycom Skype Meeting Video Interop for Skype for Business”
    “SPE_E5” = “Microsoft 365 E5”
    “SPE_E3” = “Microsoft 365 E3”
    “ATA” = “Advanced Threat Analytics”
    “MCOPSTN2” = “Domestic and International Calling Plan”
    “FLOW_P1” = “Microsoft Flow Plan 1”
    “FLOW_P2” = “Microsoft Flow Plan 2”

Leave a Reply

Your email address will not be published. Required fields are marked *