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