We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Microsoft 365 licenses information

December 31, 2024 Views: 1664

The script generates a report that includes information on Microsoft 365 licenses. The report will include numbers of available and used licenses in all registered tenants. To execute the script, create a report with corresponding custom columns. The report should have no scope or parameters

Parameters:

  • $sumLicensesColumn - Specifies the identifier of the custom column that will store the full number of licenses (sum of available and used). To get the identifier:
    1. In the Report-specific columns section, on the Columns tab, right-click the custom column.
    2. In the context menu, navigate to Copy and click Column ID.
    3. The column identifier will be copied to clipboard.
  • $availableLicensesColumn - Specifies the identifier of the custom column that will store the number of available licenses.
  • $usedLicensesColumn - Specifies the identifier of the custom column that will store the number of used licenses.
  • $tenantColumn - Specifies the identifier of the custom column that will store the name of the Microsoft 365 tenant.
  • $licensseSKUs - Specifies the SKU part numbers of the licenses to be included into the report. To include all licenses ib all tenants, set the variable to an empty array.
Edit Remove
PowerShell
$sumLicensesColumn = "{d69bd562-5ba2-4302-90da-02d27d4bd8a7}" # TODO: modify me
$availableLicensesColumn = "{e148141d-755f-4bc8-bf40-6e5f1cfc44ad}" # TODO: modify me
$usedLicensesColumn = "{c1d48810-9fdd-4de3-ab5e-d6c2c9245eba}" # TODO: modify me
$tenantColumn = "{98882249-54a0-4f99-be40-da24c1221c44}" # TODO: modify me
$licensseSKUs = @("DEVELOPERPACK_E5", "FLOW_FREE") # TODO: modify me

# Find all Microsoft 365 tenants
$configurationContainerPath = $Context.GetWellKnownContainerPath("CloudServicesO365")
$tenantSearcher = $Context.BindToObject($configurationContainerPath)
$tenantSearcher.Criteria = New-AdmCriteria "adm-O365Tenant"
$tenantSearcher.SearchScope = "ADS_SCOPE_SUBTREE"

try
{
    # Execute search
    $tenantSearchResultIterator = $tenantSearcher.ExecuteSearch()
    $tenants = $tenantSearchResultIterator.FetchAll()

    foreach ($tenantID in $tenants)
    {
        # Bind to the Tenant
        $tenant = $Context.BindToObject($tenantID.AdsPath)
        
        foreach ($sku in $tenant.Skus)
        {
            if ($licensseSKUs.Count -ne 0 -and $licensseSKUs -notcontains $sku.SkuPartNumber)
            {
                continue
            }
            
            # Get license plan display name
            if (-not([System.String]::IsNullOrEmpty($sku.CustomDisplayName)))
            {
                $skuDisplayName = $sku.CustomDisplayName
            }
            else
            {
                $skuDisplayName = $sku.DefaultDisplayName
            }            
                $Context.Items.Add(-1, $skuDisplayName, "License", @{ 
                $sumLicensesColumn = $sku.TotalUnits; 
                $availableLicensesColumn = $sku.TotalUnits - $sku.ConsumedUnits; 
                $usedLicensesColumn = $sku.ConsumedUnits;
                $tenantColumn = $tenant.TenantName
            })
        }
    }
}
finally
{
    # Release resources
    if ($tenantSearchResultIterator){ $tenantSearchResultIterator.Dispose() }
}
Comments 6
avatar
David Jenkins Aug 24, 2023
What does this line do?

$licenseNameToSkuPartNumber = @{}

It seems like it should be populated with data later but is not.
avatar
Support Aug 24, 2023
Hello David,

Thank you for pointing this out. You are right, the line is not required in the script. We removed it.
avatar
Ilia Goldenberg Oct 30, 2024
Hi,

Is there a way to filter and display only the Active SKUs, excluding all Disabled, Expired, etc.?
avatar
Support Oct 30, 2024
Hello Ilia,

Unfortunately, there is no such possibility.
avatar
Michael Kennedy Dec 30, 2024
Is there a way this script could be enhanced so it only displays certain SKUs? There are really only one or two I care to track on a daily basis about and I would like to make them into charts.

Thank you!
avatar
Support Dec 31, 2024
Hello Michael,

Yes, we updated the script accordingly (the $licensseSKUs variable was added).
Leave a comment
Loading...

Got questions?

Support Questions & Answers