Create a Free Interactive License Usage Report for Microsoft 365

Over-licensing in Microsoft 365 can lead to unexpectedly high costs, but these expenses can be easily controlled with the right visibility. Unfortunately, Microsoft doesn’t provide built-in tools to give you a clear breakdown of your licensing usage. Instead, you need additional scripts or third-party tools to gain the insights necessary for optimising your licenses effectively.

To address this issue, I’ve created a simple script that generates an interactive HTML report to help you:

  • Identify all Microsoft 365 products, their renewal dates, and any unused licenses.
  • Highlight licensed users who haven’t signed in for the past 90 days.
  • Detect privileged accounts that may be over-licensed.

In this article, I’ll walk you through the setup and execution of the script, so you can generate a comprehensive Microsoft 365 license usage report with ease.

Before you run the script

Before running the Microsoft 365 License Usage Report script, you must ensure that the required Microsoft Graph modules are installed. Due to the complexity of the Microsoft Graph SDK, the script does not attempt to install these modules automatically. Instead, you’ll need to install them manually:

  • Microsoft.Graph.Authentication
  • Microsoft.Graph.Beta.Users
  • Microsoft.Graph.Identity.DirectoryManagement

If you’re unfamiliar with installing PowerShell modules, check out my guide: How To Install the Microsoft Graph PowerShell Module. Alternatively, I explore Microsoft Graph PowerShell in greater depth in my book, which you can find in the sidebar.

The script also requires specific permissions to function correctly:

  • User.Read.All
  • AuditLog.Read.All
  • Organization.Read.All
  • RoleManagement.Read.Directory

These do not need manually consenting to however, when you run the script it will automatically check for these permissions and connect with them if required. Upon which you will be asked to grant consent with a Global Administrator user account.

Installing the script

I have published the Microsoft 365 License Usage Report script to the Microsoft PowerShell Gallery, making it publicly available for anyone to download. To install the script, simply run the following command:

Install-Script -Name Invoke-M365LicenseReport

You may be prompted to install from an untrusted gallery or update the NuGet package, simply accept both prompts to proceed. You can find the script directly on the PowerShell Gallery here: Invoke-M365LicenseReport.

Running the M365 License Usage Report script

The script itself is very easy to run and takes just seconds to complete. The only parameter you need to specify is the output path for the report, like this:

Invoke-M365LicenseReport -outpath C:\temp

Once the script completes, it will display the file path as the sole output in the console, like this:

M365 License Report Script completion

The HTML report includes a few interactive filters to help you refine the data:

  • Show only subscriptions with unused licenses – Filters the top table and summary cards to display only products with unused licenses.
  • Hide free/promotional licenses – Filters the top table and summary cards to exclude free or promotional licenses, such as Windows Store for Business, Microsoft Power Automate Free, Power Virtual Agents Viral Trial and Rights Management Adhoc.
  • Hide trial licenses – Filters the top table and summary cards to display only paid licenses.
M365 License Usage Report Script Output
M365 License Usage Report Script Output

Daniel Bradley

Daniel Bradley is a UK-based technical architect and Microsoft MVP in Security. He specialises in Microsoft Entra, Intune, and Microsoft Graph PowerShell and is the author of Microsoft Graph PowerShell for Administrators. He writes and edits Our Cloud Network using experience gained from working with Microsoft cloud environments.

This Post Has 27 Comments

  1. Jonathan

    Hi Daniel, I am receiving the following error when running the script report:

    Invoke-M365LicenseReport -outpath C:\temp
    Invoke-M365LicenseReport: The term ‘Invoke-M365LicenseReport’ is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    1. Daniel

      Hi Jonathan,

      After installing, start a new session in PowerShell and try again 🙂

  2. bhasker

    this is an awesome report. i am going to try and comment back.

  3. Rob

    tried running this in powershell ISE.
    This did not seem to work.

    tried running with powershell V7
    got the below errors. script did appear to run as i did get an output

    PS C:\Reports> Invoke-M365LicenseReport -outpath C:\Reports
    Not connected to Microsoft Graph. Connecting now…
    Successfully connected to Microsoft Graph
    Get-MgBetaUser: C:\Program Files\WindowsPowerShell\Scripts\Invoke-M365LicenseReport.ps1:92
    Line |
    92 | $AllUsers = Get-MgBetaUser -All -Property Id, accountenabled, Display …
    | ~~~~~~~~~~~~~~
    | The term ‘Get-MgBetaUser’ is not recognized as a name of a cmdlet, function, script file, or executable program.
    | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    Get-MgDirectorySubscription: C:\Program Files\WindowsPowerShell\Scripts\Invoke-M365LicenseReport.ps1:99
    Line |
    99 | $directorySubscription = Get-MgDirectorySubscription
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | The term ‘Get-MgDirectorySubscription’ is not recognized as a name of a cmdlet, function, script file, or
    | executable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    | and try again.
    HTML report generated at C:\Reports\M365_License_Usage_Report.html

    1. Daniel

      Thanks for the feedback Rob, I’ll remove dependencies on other modules in the next version!

  4. jack

    I’ve confirmed all required modules are present, returns error

    $licenses = get-MgSubscribedSku | Where {$_.CapabilityStatus -eq ‘Ena …
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | One or more errors occurred. (Method not found: ‘Microsoft.Graph.PowerShell.Authentication.AuthProviderType
    | Microsoft.Graph.PowerShell.Authentication.IAuthContext.get_AuthProviderType()’.)

    1. Hi Jack,

      Thanks for the feedback! I have released an updated version this morning which removed any dependencies on other Microsoft Graph PowerShell modules. Now it only requires the single Microsoft.Graph.Authentication module.

  5. Jordan

    Seems to hang once I have ran Invoke-M365LicenseReport -outpath C:\temp after saying connected to Microsoft graph with all required permissions

  6. Victor

    Hi Daniel, great report.
    Is it possible to request a switch to create an excel file instead of the html. I like the visual but would be nice to have more details and be able to filter a bit more.

    Thanks!

    1. That would certainly be possible, but would requirement more development time, which I could not do for free right now 🙂

  7. Willy

    Hello Daniel !

    Very fine ! I need a Help with,

    Invoke-M365LicenseReport.ps1: Failed to connect to Microsoft Graph: The type initializer for ‘Azure.Identity.AuthenticationRecord’ threw an exception.

    1. You should look at re-installing the Microsoft.Graph.Authentication module. Try in PowerShell 7 too 🙂

  8. chris horsted

    Hi Daniel. Has anyone run this against a large tenant? I am currently running it and it has been running for 12 hours so far

    1. Hey Chris, how many users are we talking? Obtaining all users should be fairly fast, but the PIM API’s are slow to obtain directory roles. For very large tenants, the HTML report may not be the best output, but I’ve run it for around 20k users just fine 🙂

  9. Scott

    How do we run this against multiple tenants. When I close and re-open Powershell it would usually forget the previous tenant I was logged into. But for some reason with your script it has remembered the first tenant I was logged into.
    Attempted to Get-PSSession | Remove-PSSession but this has stil kept me logged in.

  10. Duban Felipe Moreno

    Hi,

    I like this script, I would like to add that it would be good to disconnect the session at the end. With the command Disconnect-MgGraph

    This would be very useful because I manage several tenants and I see that the session remains connected.

    1. Daniel

      Thanks Duban, I may add it, but do not feel that would be so important right now :~)

  11. Alexandre

    Hello, Daniel, your work is amazing.

    I have a challenge, see if this is possible.

    Let’s say in a scenario:

    When adding a license, show its value, trigger an alert that this license will be provisioned for 30 days and at the end of this period, if the user does not respond, the license will be deprovisioned.

    1. Dan

      I represent a MSP and we automated the cleanup any unassigned licenses at renewal. Sounds like what you’re also trying to do is determine whether the user is using the license, which is another problem entirely.

      1. Yeah, I’m not bothered about truing down at renewal, that’s the easy bit, instead I want to uncover incorrect process or configuration in a customers environment, bearing in mind our customers range from 1,000 users to 100,000 users.

  12. Bantu

    What is Detect privileged accounts that may be over-licensed?

  13. AusSupport

    Hi Daniel,

    How do we schedule to run and send an email.

Leave a Reply