GuidesHow to Check Office 365 License Usage & History

How to Check Office 365 License Usage & History

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

The Get-MsolUser PowerShell cmdlet plays an important role when managing Office 365 Windows Azure Active Directory. Get-MsolUser can be very handy in daily operational tasks related to Office 365 WAAD.

One of the tasks that Office 365 systems administrators are responsible for is monitoring and managing Office 365 licenses and services that are assigned to each Office 365 user. Windows Server Tutorials

This information helps organizations plan for IT budgets, save money by removing licenses from users that no longer use Office 365, and control the assignment of Office 365 licenses and services.

This article highlights some valuable Office 365 PowerShell commands and scripts that can help you easily obtain the license information for all Office 365 users and view those reports in either the PowerShell window or a .CSV file.

If you have installed Microsoft Online Sign-In Assistant for IT Professional and Windows Azure Active Directory Module for Windows, you can execute the PowerShell commands/scripts explained in this article.

Getting Licensed Office 365 Users

A user must be assigned an Office 365 license before he or she can use Office 365 services. The license can be assigned during the user creation process or at a later point of time.

To get the list of users that are assigned an Office 365 license and store the output in a .CSV file, you can run this command:

Get-MSOluser -ALL | Select-Object UserPrincipalName, DisplayName, IsLicensed | Export-CSV AllLicensedUsers.CSV -NoTypeInformation

Get-MSOlUser identifies the “IsLicensed” attribute for every user that is set to “True,” which indicates that an Office 365 user is assigned an Office 365 license. The command retrieves the User Principal Name, Display Name and value assigned to the “IsLicensed” property for each user.

In cases where you need to view the list of Office licenses and services assigned to a particular user, you can use this PowerShell cmdlet:

$GetUserLicenses = Get-MsolUser -UserPrincipalName "Rick@ExampleIT.OnMicrosoft.com" | Select-Object userPrincipalName -ExpandProperty Licenses
$GetUserLicenses.ServiceStatus

And if you wish to retrieve the licensing information for all Office 365 users, replace the “-UserPrincipalName” parameter with the “-ALL” parameter as shown in this command:

$GetUserLicenses = Get-MsolUser -All "Rick@ExampleIT.OnMicrosoft.com" | Select-Object userPrincipalName -ExpandProperty Licenses
$GetUserLicenses.ServiceStatus

These commands display the output in the PowerShell window, but this output might not be as useful as you need.

Instead, you can create a script to store the information in a .CSV file and then run the script daily to ensure you have an up-to-date account of the Office 365 licenses assigned to users. You can then use the report to remove licenses as needed.

Getting Licenses Count for All Users

First use a command to get a list of users in Office 365 Tenant, a count of Office 365 Plans that you have bought, the total Office 365 licenses available, and the count of licenses assigned to Office 365 users. Use this PowerShell script to get that information in a .CSV file:

    $LicenseReport = "C:TempLicenseReport.CSV"
    IF (test-Path $LicenseReport)
    {
Remove-item $LicenseReport
    }
    $AllUsers = (Get-MSOluser -ALL).Count
    $TotalLicenseUsers = (Get-msoluser -ALL | Select-Object UserPrincipalName -ExpandProperty licenses).Count
    $PlanCount = (Get-MsolAccountSku).Count
    $TotalLicenses = Get-MsolAccountSku | Measure-Object ActiveUnits -Sum
    $STR = "Total Users: "+$AllUsers
    Add-Content $LicenseReport $STR
    $STR = "Total Office 365 Plans: "+$PlanCount
    Add-Content $LicenseReport $STR
    $STR = "Total Office 365 Licenses in Plan: "+$TotalLicenses.Sum
    Add-Content $LicenseReport $STR
    $STR = "Total Licenses Assigned: "+$TotalLicenseUsers
    Add-Content $LicenseReport $STR

That PowerShell script generates a report named LicenseReport.CSV in the C:Temp folder. The script removes the previous report file and generates a new one every time you run it.

A report generated by using that script looks like this:

Office 365 PowerShell Report #1

Getting Licenses Assigned to each Office 365 User

Perhaps you need more specific information than a total count of licenses for all Office 365 Users. Instead, you might need a report that contains the Office 365 user name and Office 365 Plan, licenses, and services assigned to each user. You can use this PowerShell script to pull that report:

    $UserLicFile="C:TempUserLicensesPerUser.CSV"
    IF (test-Path $UserLicFile)
    {
    Remove-Item $UserLicFile
    }
    $STR = "User Principal Name, Office 365 Plan, Office 365 Service,Service Status"
    Add-Content $UserLicFile $STR
    $GetAllUsers=Get-MsolUser -All | Select-Object UserPrincipalName -ExpandProperty Licenses
    ForEach ($AllU in $GetAllUsers)
    {
    $SelUserUPN = $AllU.UserPrincipalName
    $T = $AllU
    $i = 0
    ForEach ($AllITems in $T)
    {
    $T.Count
    $T[$i].AccountSkuId
    $Account = $T[$i].AccountSkuId
    $TTT = $T[$i].ServiceStatus
    ForEach ($AllR in $TTT)
    {
    $GR = $AllR.ServicePlan.ServiceType
    $GZ = $AllR.ProvisioningStatus
    $STRNow = $SelUserUPN + "," + $Account + "," + $GR + "," + $GZ
    Add-Content $UserLicFile $STRNow
    }
    $i = $i + 1
    }
    }

That PowerShell script generates a report file in .CSV format that contains the license information for all of your Office 365 users.

Below is a sample report generated by this PowerShell script. It displays the Office 365 user principal name to which the office 365 license is assigned, the Office 365 plan from which the license is assigned, Office 365 Services that are assigned, and the status of individual services.

Office 365 PowerShell Report #2

To help you get a clear picture of the Office 365 licenses in use in your organization, you will want to run both of the scripts provided in this article.


Nirmal Sharma is a MCSEx3, MCITP and Microsoft MVP in Directory Services. He specializes in directory services, Microsoft Azure, Failover clusters, Hyper-V, System Center and Exchange Servers, and has been involved with Microsoft technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to Health Packs for ADHealthProf.ITDynamicPacks.Net solutions. Nirmal can be reached at nirmal_sharma@mvps.org.

Follow ServerWatch on Twitter and on Facebook

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories