SOLVED

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

Iron Contributor

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

@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

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}

@VasilMichev Thanks for the reply,

 

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

I tried adding an export function to it like above but it seems i'm only getting the fist group on the list.
But i can see that you are looping through all the groups.
Am i missing something.

I need it to export all the groups in the list to the csv

 

Thanks in Advance

best response confirmed by Patrick Rote (Iron Contributor)
Solution

Use the -Append switch for Export-CSV.

Thanks that actually did work .
Although i found out i could loop through the members too
1 best response

Accepted Solutions
best response confirmed by Patrick Rote (Iron Contributor)