How can I output the ADGroup name and the email address members of ADGroups with name of group starting with 'MY-GROUP*' I manage to export all the desired groups but I'm struggling to get only the email.
> $adgroups = Get-ADGroup -Filter {Name -like 'MY-GROUP*'} | sort
> name
>
> $data = foreach ($adgroup in $adgroups) {
> $members = $adgroup | get-adgroupmember | sort name
> foreach ($member in $members) {
> [PSCustomObject]@{
> Group = $adgroup.name
> Members = $member
> }
> } } $data | select Group, Members
The desired output would something like this :
| GroupName | mail |
| --------- | --------------- |
| MY-GROUP-1 | [email protected]|
| MY-GROUP-1 | [email protected]|
| MY-GROUP-1 | [email protected]|
| MY-GROUP-2 | [email protected]|
| MY-GROUP-2 | [email protected]|
| MY-GROUP-2 | [email protected]|
| MY-GROUP-3 | [email protected]|
| MY-GROUP-3 | [email protected]|