I am trying to build a script that can get a list of members of a distribution group recursively, and then output the data in a way that is manipulable.
The below code works fine so far, but only outputs a final list of recipients on the screen, with two columns (Name, RecipientType). I have tried a couple of ways to instead output the results to a variable or array in order to manipulate it, however none of them have worked.
What would be the best way to take the $Member
variable, and add it to another variable or array?
function Get-DistributionGroupMemberRecursive ($Identity) {
$GroupMembers = Get-DistributionGroupMember -Identity $Identity
foreach ($Member in $GroupMembers) {
if($Member.RecipientType -like "*Group") {
Get-DistributionGroupMemberRecursive -Identity $Member.Identity
}
else {
$Member
}
}
}
Get-DistributionGroupMemberRecursive -Identity some_address@domain