Get AD members (including contacts) name & E-mails

Hello,

 

I have a short line for the above mentioned:

Get-ADGroup "group" -Properties member | Select-Object -ExpandProperty member | Get-ADObject | select name | sort name

which provides the names of the group members.
i want the email addresses of the users and contacts.
I’ve tried: select name,e-mail / name,emailaddress / name,mail - nothing worked for me, all returned empty <>

Please Help, thanks.

You could use Get-ADGroupMemeber and Get-ADUser together to achieve this

Get-ADGroupMember "group" | Get-ADUser -Properties mail | Select-Object -Property Mail

thanks but it’s return only the emails and only of the users, without contacts

Read the below thread which will give you some idea

https://powershell.org/forums/topic/get-active-directory-contact-information/

Hi,

Get-adgroupmember does not include contacts.

https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adgroupmember?view=win10-ps
The Get-ADGroupMember cmdlet gets the members of an Active Directory group. Members can be users, groups, and computers.

You need to do it the other way by finding adobjects who are member of the desired group.

[pre]

$group = get-adgroup ‘group’ | select -ExpandProperty distinguishedname
Get-ADObject -filter * -Properties memberof,mail | where {$group -contains $_.memberof} | select mail

[/pre]

[quote quote=178980]Hi,

Get-adgroupmember does not include contacts.

https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adgroupmember?view=win10-ps

The Get-ADGroupMember cmdlet gets the members of an Active Directory group. Members can be users, groups, and computers.

You need to do it the other way by finding adobjects who are member of the desired group.

PowerShell
5 lines
<textarea class="ace_text-input" wrap="off" autocorrect="off" autocapitalize="off" spellcheck="false" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;"></textarea>
1
2
3
4
5
$group = get-adgroup 'group' | select -ExpandProperty distinguishedname
Get-ADObject -filter * -Properties memberof,mail | where {$group -contains $_.memberof} | select mail
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote]

Thanks, that worked for me