Search code examples
azurepowershellazure-active-directoryactive-directory

Azure AD Attributes query does not yield existing data


We are using Azure Active Directory in an hybrid mode with our on premise AD.

I am trying to get "manager" and "companyName" attributes from Azure AD Accounts, those accounts do not exists on Active Directory on premise.

The attributes I am trying to get are empty, but they are shown on the "Microsoft Entra ID" GUI.

I am using PowerShell(Get-AzADUser) with the module AZ, I also tried GraphAPI directly, no results.

Is the issue, that those attributes should come from AD on premise synchronization ? Is there a way around this ?enter image description here


Solution

  • Note that, you won't get these attributes in PowerShell response if that user does not have those properties values updated on the "Microsoft Entra ID" GUI.

    I have one Azure AD user named Sridevi with both companyName and Manager properties as below:

    enter image description here

    Initially, I connected to Microsoft Graph with User.Read.All permission by running below PowerShell command:

     Connect-MgGraph -Scopes "User.Read.All"
    

    Response:

    enter image description here

    Now, I used below script to get companyName and Manager properties of user via PowerShell:

    $user = Get-MgUser -UserId "userId" -ExpandProperty "Manager" -Property "displayName, companyName, manager"
    
    $manager = $user.manager
    $managerName = $null
    
    if ($manager -ne $null) {
        $managerDetails = Get-MgUser -UserId $manager.id -Property "displayName"
        $managerName = $managerDetails.displayName
    }
    
    $user | Select-Object displayName, companyName, @{Name="ManagerName"; Expression={$managerName}}
    

    Response:

    enter image description here

    You can make use of below modified script to get the same properties of all Azure AD users:

    $allUsers = Get-MgUser -All -ExpandProperty "Manager" -Property "displayName, companyName, manager"
    
    foreach ($user in $allUsers) {
        $manager = $user.manager
        $managerName = $null
    
        if ($manager -ne $null -and $manager.id -ne $null) {
            $managerDetails = Get-MgUser -UserId $manager.id -Property "displayName"
            $managerName = $managerDetails.displayName
        }
    
        $user | Select-Object displayName, companyName, @{Name="ManagerName"; Expression={$managerName}}
    }
    

    Response:

    enter image description here