Forum Discussion

Patrick Rote's avatar
Patrick Rote
Iron Contributor
Sep 30, 2020
Solved

How to get all users exported from an AD AzureGroup listing their,email addresses?

Hi All,
How to get all users exported from an AD AzureGroup listing their,email addresses e.g a group starting with "HRUSERS"

Do i need to install a module for powershell?
Thanks in advance

6 Replies

  • PowerShell is the best way to do this, you'll need the AzureAD or the MSOnline module. Here's a sample for the former:

     

    Get-AzureADGroup -SearchString GroupName | Get-AzureADGroupMember | select DisplayName,UserPrincipalName | Export-Csv -nti blabla.csv

    • Patrick Rote's avatar
      Patrick Rote
      Iron Contributor

      VasilMichev Thanks so much for the response.
      When i ran the command it worked but how can i add another field showing the actual group name ( e.g something like this 

      GroupName | DisplayName(This is the name of the user) | UserPrincipleName(Email address)

       

      The searchstring  i used is for example is "Test" but there are groups with names Test1,Test 123,Test456

       

      So what i need is something like this :-

       

      GroupName | DisplayName(This is the name of the user) | UserPrincipleName(Email address)

      Test1              Peter O                                                         po@email
      Test123          Michael Dunns                                              md@email

       

      Is this possible?

       

      Thanks in Advance

      • VasilMichev's avatar
        VasilMichev
        MVP

        That's a bit more complicated, as in it requires a more convoluted piece of code to fit in a single line.

         

        $groups = Get-AzureADGroup -SearchString TeamOne
        foreach ($group in $groups) { Get-AzureADGroupMember -ObjectId $group.ObjectId | select @{n="GroupName";e={$group.DisplayName}},DisplayName,UserPrincipalName}
        

Resources