Forum Discussion

Samer Forever's avatar
Samer Forever
Copper Contributor
Jul 23, 2018

How the export Azure AD security group members email addresses into CSV?

Hi Forum,

How the export Azure AD security group members email addresses into CSV?

I tried this PowerShell command:

Get-AzureADGroupMember -ObjectId "xxxx...." | Export-csv -path C:\Temp\Output.csv

But, It only generated IDs. How can I get the members email addresses?

please, Let me know!

6 Replies

  • Anonymous's avatar
    Anonymous
    you'll want to pipe in between there the get-azureaduser in between there to get the user details. so something like get-azureadgroupmember -objectid "xxx" | get-azureaduser | export etc. etc.
    • VasilMichev's avatar
      VasilMichev
      MVP

      There's no need for that, as the AAD module returns the full object, it's simply not shown in the default formatting. So for example, this will do the trick:

       

      Get-AzureADGroupMember -ObjectId 84b18857-3c01-48be-b707-492019c57142 | select UserPrincipalName,ProxyAddresses | Export-Csv -nti blabla.csv

      • Anonymous's avatar
        Anonymous
        actually Max's response would work too, I was still asleep this morning, I would take back my response lol.
  • Max Fritz's avatar
    Max Fritz
    Iron Contributor

    Get-AzureADGroupMember -ObjectId "xxxxx" | select mail | Export-Csv


    If you'd like to export all attributes of the users, run this:

    Get-AzureADGroupMember -ObjectId "xxxxx" | fl | Export-Csv

    • whatch's avatar
      whatch
      Copper Contributor

      Is there a way to run this script so that I don't have to look up the objectID every time I run the script. I want to run this based on principal name (Email Address).

      • SimBur2365's avatar
        SimBur2365
        Brass Contributor
        How about this to allow you to input the email address of the group?

        $groupmail = Read-Host -Prompt "Enter the group email address"
        $groupfind = Get-AzureADGroup -All $true | Where-Object { $_.mail -eq $groupmail }
        Get-AzureADGroup -ObjectId $groupfind.ObjectId | Get-AzureADGroupMember

        You can also try this script - it will output all Azure AD groups and members - easily modified to include additonal information in the output.
        https://www.howdoiuseacomputer.com/index.php/2021/09/12/azure-ad-output-groups-and-members-to-csv/

Resources