Exporting AAD Licenses and on prem AD attributes

Comp_tech 20 Reputation points
2023-05-12T11:02:43.49+00:00

Hi everyone,

I am trying to export some information from AAD via MSGraph PowerShell. I am not sure if the information I want to export can be done this way and hoping someone can help me or at least confirm if it's possible to export it.

1- Is it possible to export on prem AD Extension Attributes? ie ExtensionAttribute2, ExtensionAttribute3 (They are already syncing to AAD)

2- Can you include direct and group level license assignment information?

Below is the script I am using but couldn't get these 2 options working and not sure if it can be done.

$users = @()

$members = Get-MgUser -All
            
foreach ($member in $members) {
    $user = Get-MgUser -UserId $member.Id -Property ID, DisplayName, UserPrincipalName, companyName | Select-Object ID, DisplayName, UserPrincipalName, companyName
                $licenses = $null
                $licenses = (Get-MgUserLicenseDetail -UserId $User.id).SkuPartNumber 
                foreach ($license in $licenses ) {
                    #Write-Host "Licenses found for $($User.DisplayName): $license"
                    if($license -ne 'FLOW_FREE'){ 
                    if($license -ne 'POWER_BI_STANDARD'){
                    $users += [PSCustomObject]@{
                        ID                   = $user.ID
                        USERPRINCIPALNAME    = $user.UserPrincipalName               
                        Name                 = $user.DisplayName                                        
                        Licenses             = $license
                        companyName          = $user.CompanyName}
                        
                        
                    }  
                  
            }
    }
}

Thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,448 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,328 questions
0 comments No comments
{count} votes