SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1733179%22%20slang%3D%22en-US%22%3EHow%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1733179%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3CBR%20%2F%3EHow%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%20e.g%20a%20group%20starting%20with%20%22HRUSERS%22%3C%2FP%3E%3CP%3EDo%20i%20need%20to%20install%20a%20module%20for%20powershell%3F%3CBR%20%2F%3EThanks%20in%20advance%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1733179%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1733391%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1733391%22%20slang%3D%22en-US%22%3E%3CP%3EPowerShell%20is%20the%20best%20way%20to%20do%20this%2C%20you'll%20need%20the%20AzureAD%20or%20the%20MSOnline%20module.%20Here's%20a%20sample%20for%20the%20former%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGet-AzureADGroup%20-SearchString%20GroupName%20%7C%20Get-AzureADGroupMember%20%7C%20select%20DisplayName%2CUserPrincipalName%20%7C%20Export-Csv%20-nti%20blabla.csv%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1733469%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1733469%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3BThanks%20so%20much%20for%20the%20response.%3CBR%20%2F%3EWhen%20i%20ran%20the%20command%20it%20worked%20but%20how%20can%20i%20add%20another%20field%20showing%20the%20actual%20group%20name%20(%20e.g%20something%20like%20this%26nbsp%3B%3C%2FP%3E%3CP%3EGroupName%20%7C%20DisplayName(This%20is%20the%20name%20of%20the%20user)%20%7C%20UserPrincipleName(Email%20address)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20searchstring%26nbsp%3B%20i%20used%20is%20for%20example%20is%20%22Test%22%20but%20there%20are%20groups%20with%20names%20Test1%2CTest%20123%2CTest456%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20what%20i%20need%20is%20something%20like%20this%20%3A-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGroupName%20%7C%20DisplayName(This%20is%20the%20name%20of%20the%20user)%20%7C%20UserPrincipleName(Email%20address)%3C%2FP%3E%3CP%3ETest1%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Peter%20O%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bpo%40email%3CBR%20%2F%3ETest123%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Michael%20Dunns%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20md%40email%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20this%20possible%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20Advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1735481%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1735481%22%20slang%3D%22en-US%22%3E%3CP%3EThat's%20a%20bit%20more%20complicated%2C%20as%20in%20it%20requires%20a%20more%20convoluted%20piece%20of%20code%20to%20fit%20in%20a%20single%20line.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24groups%20%3D%20Get-AzureADGroup%20-SearchString%20TeamOne%0Aforeach%20(%24group%20in%20%24groups)%20%7B%20Get-AzureADGroupMember%20-ObjectId%20%24group.ObjectId%20%7C%20select%20%40%7Bn%3D%22GroupName%22%3Be%3D%7B%24group.DisplayName%7D%7D%2CDisplayName%2CUserPrincipalName%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1737755%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20get%20all%20users%20exported%20from%20an%20AD%20AzureGroup%20listing%20their%2Cemail%20addresses%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1737755%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20reply%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24groups%20%3D%20Get-AzureADGroup%20-SearchString%20TeamOne%0Aforeach%20(%24group%20in%20%24groups)%20%7B%20Get-AzureADGroupMember%20-ObjectId%20%24group.ObjectId%20%7C%20select%20%40%7Bn%3D%22GroupName%22%3Be%3D%7B%24group.DisplayName%7D%7D%2CDisplayName%2CUserPrincipalName%20Export-Csv%20-nti%20GetTestGroupMembers.csv%0A%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20tried%20adding%20an%20export%20function%20to%20it%20like%20above%20but%20it%20seems%20i'm%20only%20getting%20the%20fist%20group%20on%20the%20list.%3CBR%20%2F%3EBut%20i%20can%20see%20that%20you%20are%20looping%20through%20all%20the%20groups.%3CBR%20%2F%3EAm%20i%20missing%20something.%3C%2FP%3E%3CP%3EI%20need%20it%20to%20export%20all%20the%20groups%20in%20the%20list%20to%20the%20csv%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20Advance%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent 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

@Vasil Michev 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}

@Vasil Michev 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 (Frequent 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