0 votes

I'm trying to retrive the Microsoft 365 License product name in a report as the 'Office 365 License' attribute in Adaxes shows each individual licensed product e.g. Exchange etc. We're trying to get a report of each of the different license types into a report in Adaxes for additional action.

So far I have the below however it's not retrieving values even though if a run the script in powershell it works perfectly. Product names from the article here

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

$user = $Context.BindToObjectByDN("%distinguishedName%")
$Context.GetOffice365Credential($user)

Connect-MsolService -Credential

$MSOLUser = Get-MsolUser -UserPrincipalName "%userPrincipalName%"
$Licenses = ($MSOLUser.Licenses.AccountSkuId).Trim("%company%:")

$productnames = @()
Foreach ($License in $Licenses) {
    If ($License -eq "ENTERPRISEPACK") {$productnames += "Office 365 E3"}
    Elseif ($License -eq "DESKLESSPACK") {$productnames += "Office 365 F3"}
    ElseIf ($License -eq "SPE_E3") {$productnames += "Microsoft 365 E3"}
    ElseIf ($License -eq "SPE_F1") {$productnames += "Microsoft 365 F3"}
    }
$productnames = $productnames -join ", "


$Context.Value = $productnames
by (260 points)

1 Answer

0 votes
by (272k points)
selected by
Best answer

Hello Richard,

Use the below script to add names of assigned Microsoft 365 licenses to the custom column. The column type should be Text.

$ADObject = $Context.GetADObject()
try
{
    $microsoft365properties = $ADObject.GetOffice365Properties2()
}
catch
{
    $microsoft365properties = $NULL
}

if ($NULL -ne $microsoft365properties)
{
    $licenses = @()
    foreach ($license in $microsoft365properties.Licenses)
    {
        if (!$license.Assigned)
        {
            continue
        }

        $licenseName = $license.Sku.DisplayName
        $licenses += $licenseName
    }

    $stringValue = [System.String]::Join(";", $licenses)
    $Context.Value = $stringValue
}
else
{
    $Context.Value = "No tenant associated with user"
}

Related questions

0 votes
1 answer

Hi I'm trying to product a report to show the users with either E3, F3 or F5 licenses. If I add the Adaxes "Microsoft 365 Licenses" attribute directly to the report then ... from the user and show a nice "Microsoft E3" etc value. Is this possible? Thanks

asked Sep 27, 2021 by chappers77 (2.0k points)
0 votes
1 answer

Hi, I try to make a report for our SAM to show all users with a specific license. But I fail to even find anything. I tried, among many ... .DirectorySearcher.AppendFilter("(adm-O365AccountLicenses=POWER_BI_STANDARD)") But I get nothing. Please advice.

asked May 20, 2021 by KristofferJ (80 points)
0 votes
1 answer

We need to capture the Office365 (if any) on the user account before we disable. These are accounts taht are temps or contractors that we disabled and re enable for ... Example of group name is Office-E3-EXO and we want to capture it to CustomAttributeText31

asked Aug 4, 2020 by willy-wally (3.2k points)
0 votes
1 answer

Hi I'm trying to add your report from here but whenever I run it, I get 2 errors for each user which seem to correspond to the following 2 lines in the ... "user" $Context.DirectorySearcher.AddCriteria($criteria) But I still get the same error's. Thanks Matt

asked Oct 16, 2023 by chappers77 (2.0k points)
0 votes
2 answers

I am trying to create a report-specific column (DateTime - Regular Date) where I can extract the datetime from the description field of the user object using a regular ... () $line = $object.Get("description") $dateTime = ?? $Context.Value = $dateTime

asked Feb 27 by emeisner (60 points)
3,346 questions
3,047 answers
7,772 comments
544,972 users