Export all users to a CSV file with all OnPremisesExtensionAttributes

Bühler Gabriel 76 Reputation points
2023-01-24T14:15:01.5266667+00:00

Hey Guys

I am trying to set up a small script that exports all my AzureAD Users with all their ExtensionAttributes into a CSV-File. Best would be to have a Line for each User with all their Properties. Here is what I have so far:

 Get-MgUser  | Where-Object {$_.UserPrincipalName -Like "*companyname.com"} | Select-Object DisplayName,onPremisesExtensionAttributes -ExpandProperty onPremisesExtensionAttributes | Format-Table DisplayName, ExtensionAttribute1, ExtensionAttribute2, ExtensionAttribute3, ExtensionAttribute4, ExtensionAttribute5, ExtensionAttribute6, ExtensionAttribute7, ExtensionAttribute8, ExtensionAttribute9, ExtensionATtribute10, ExtensionAttribute11, ExtensionAttribute12, ExtensionAttribute13, ExtensionAttribute14, ExtensionAttribute15 | Export-CSV -Append -Delimiter ";"

But it unfortunately just shows up empty...do you may see what I am doing wrong?

Thank you for your help.

Kind regards,

Gabe

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,364 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,299 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,529 questions
{count} votes

Accepted answer
  1. Vasil Michev 99,941 Reputation points MVP
    2023-01-24T14:43:16.88+00:00

    For starters, you need to specifically request the properties, as by default Get-MgUser returns only a small subset.

    Get-MgUser -Property DisplayName,onPremisesExtensionAttributes,UserPrincipalName

    Do note that you have to request each property you plan to use, including those used for filtering. Next, don't use Format-table, as it does not mix with Export-CSV. Use another select statement instead, which gives us:

    Get-MgUser -Property DisplayName,onPremisesExtensionAttributes,UserPrincipalName | Where-Object {$_.UserPrincipalName -Like "*michev.onmicrosoft.com"}| Select-Object -ExpandProperty onPremisesExtensionAttributes | select DisplayName,UserPrincipalName,ExtensionAttribute* | Export-CSV -nti blabla.csv

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful