Script Repository

Save assigned Microsoft 365 licenses to Active Directory attribute

May 08, 2020

The script saves names of Microsoft 365 (Office 365) licenses assigned to a user to an attribute of the user's AD account. This can be used to quickly look up Microsoft 365 (Office 365) licenses assigned to multiple users. For example, you can add a column for the attribute to the Web Interface so that you are able to view assigned licenses when browsing Active Directory.

To use the script in your environment, create a Scheduled Task that runs it on a periodical basis. The task must be configured for the User object type.


  • $attributeLdapName - specifies the LDAP display name of the attribute that holds the license list.
Edit Remove
$attributeLdapName = "extensionAttribute1" # TODO: modify me

# Get Microsoft 365 properties
    $microsoft365Properties = $Context.TargetObject.GetOffice365Properties()
    return # No Microsoft 365 Account

# Get Microsoft 365 licenses available for the user
$licenses = $microsoft365Properties.Licenses

# Build a list of assigned licenses, replacing SKU part numbers with display names
$licenseNames = New-Object "System.Text.StringBuilder"
foreach ($license in $licenses)
    if (!($license.Assigned))
    [void]$licenseNames.Append($license.Sku.DisplayName + ";")

if ($licenseNames.Length -eq 0)
    # No assigned licenses: clear the attribute
    $Context.TargetObject.Put($attributeLdapName, $NULL)
    # Save license names to the attribute
    $Context.TargetObject.Put($attributeLdapName, $licenseNames.ToString())

# Save changes

Comments ( 0 )
No results found.
Leave a comment