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 (220 points)

1 Answer

0 votes
by (206k 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 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 by KristofferJ (20 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

I'm trying to use "Before Modify Office 365" event to request approval for changes. It seems to be kicking off for the "After Create User" event. How do I request ... for default settings but if admins want to make a change then it goes out for approval.

asked Jul 20, 2020 by ComputerHabit (790 points)
0 votes
1 answer

Adaxes version is 2018.2. I have build a custom report, and I don't want the 'Name' column with the pictures to appear in it. But it seem to be mandatory, it is greyed ... . Is there a way to remove / hide / or change the mandatory attribute or column ? Thanks

asked Jan 9, 2020 by Isabelle (50 points)
0 votes
1 answer

I have a Powershell script running as a schedule task that is exporting user records. I have a custom attribute, positionPrimarySupervisor, that contains the DN of the user's ... supervisor. Can you provide me a script to get the information. Thanks... Sandra

asked Oct 8, 2015 by sandramnc (730 points)
2,554 questions
2,297 answers
6,126 comments
661,999 users