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

Update report drop-down parameter with Microsoft 365 licenses

June 28, 2023 Views: 1008

The script updates the specified drop-down list parameter with display names and SKU Part Numbers of Microsoft 365 licenses in all the registered tenants. To execute the script, create a scheduled task configured for the Domain object type with a managed domain in the Activity Scope.

Parameters:

  • $reportDN - Specifies the distinguished name (DN) of the report whose parameter will be updated. For information on how to get an object DN, see Get the DN of a directory object.
  • $parameterName - Specifies the name of the report parameter to update. The name should include the param- prefix.
Edit Remove
PowerShell
$reportDN = "CN=My Report,CN=Reports,CN=Reports Root,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modfy me
$parameterName = "License" # TODO: modfy me

# Find all Microsoft 365 Tenants
$configurationContainerPath = $Context.GetWellKnownContainerPath("CloudServicesO365")
$tenantSearcher = $Context.BindToObject($configurationContainerPath)
$tenantSearcher.SearchFilter = "(objectClass=adm-O365Tenant)"
$tenantSearcher.SearchScope = "ADS_SCOPE_SUBTREE"

try
{
    $tenantSearchResultIterator = $tenantSearcher.ExecuteSearch()
    $tenants = $tenantSearchResultIterator.FetchAll()
    
    $licenseNameToSkuPartNumber = @{}
    foreach ($tenantID in $tenants)
    {
        # Bind to the Tenant
        $tenant = $Context.BindToObject($tenantID.AdsPath)
        
        foreach ($sku in $tenant.Skus)
        {
            if (!$sku.Enabled)
            {
                continue
            }
            
            # Get license plan display name
            if (-not([System.String]::IsNullOrEmpty($sku.CustomDisplayName)))
            {
                $skuDisplayName = $sku.CustomDisplayName
            }
            else
            {
                $skuDisplayName = $sku.DefaultDisplayName
            }
            
            if ($licenseNameToSkuPartNumber.Contains($skuDisplayName))
            {
                continue
            }
            
            $licenseNameToSkuPartNumber.Add($skuDisplayName, $sku.SkuPartNumber)
        }
    }
}
finally
{
    if ($tenantSearchResultIterator){ $tenantSearchResultIterator.Dispose() }
}

# Get report parameters
$report = $Context.BindToObjectByDN($reportDN)
$configuration = $report.GetConfiguration()
$parameters = $configuration.Parameters

# Update the parameter values
foreach ($parameter in $parameters)
{
    if ($parameter.Name -ne $parameterName)
    {
        continue
    }
    
    $parameterValues = @()
    foreach ($lcienseName in $licenseNameToSkuPartNumber.Keys)
    {        
        $parameterValue = $parameter.CreateValue()
        $parameterValue.DisplayName = $lcienseName
        $parameterValue.Value = $licenseNameToSkuPartNumber[$lcienseName]
        $parameterValues += $parameterValue
    }
    $parameter.Values = $parameterValues
}

# Save changes
$configuration.Parameters = $parameters
$report.SetConfiguration($configuration)
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers