Azure AD Graph Powershell: Getting an export an all users with all extension attributes and Manager's anmes

Bühler Gabriel 81 Reputation points
2023-01-25T15:30:14.27+00:00

Hey Guys

I am trying to export a list of all users, with all their extension attributes and further properties, including the manager. I am able to get all the properties needed except for the Manager's Name.

Get-MgUser -All -Property DisplayName,onPremisesExtensionAttributes,UserPrincipalName, Department, Division, City, Country, Manager | Where-Object {$_.UserPrincipalName -Like "******@company.com"}| Select-Object DisplayName,UserPrincipalName, Department, Division, City, Country, Manager -ExpandProperty onPremisesExtensionAttributes, Manager | select DisplayName,UserPrincipalName, Department, Division, City, Country,ExtensionAttribute*,  @{Name = 'Manager'; Expression = {$_.Manager.AdditionalProperties.displayName}} | Export-CSV -nti file.csv

I am able to get the Manager without the ExtensionAttributes included, by using the "ExpandProperty" setting, but I cannot "combine" it with ExtensionAttributes.

Do you may know what i can do differently?

Thank you for your help.

Kind regards,

Gabe

Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2023-01-25T16:43:28.12+00:00

    You can only expand a single property via the Select-Object cmdlet. Try this:

    Get-MgUser -All -Property DisplayName,onPremisesExtensionAttributes,UserPrincipalName, Department, Division, City, Country -Expand Manager | Select-Object DisplayName,UserPrincipalName, Department, Division, City, Country, Manager -ExpandProperty onPremisesExtensionAttributes | select DisplayName,UserPrincipalName, Department, Division, City, Country,ExtensionAttribute*, @{Name = 'Manager'; Expression = {$_.Manager.AdditionalProperties.displayName}} | Export-CSV -nti file.csv

    4 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.