Get contacts from distribution groups

Alex
Alex used Ask the Experts™
on
Afternoon all,

I need to find any contacts in any distribution groups from AD. I know that Get-adgroupmember doesn't return contacts and I'm unsure as to the best way forward.

Get-ADObject -Filter {(objectclass -eq 'group')} -Properties Member

Open in new window


I know that'll pull the members within an object but it won't filter out only contacts. Any idea how to go about this? I've had a search and not found anything that filters contacts before the output.

Thanks
Alex
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
No need for Get-ADObject. You can use Get-ADGroup, get the Member property, expand the Member property (the DN), get the object, filter for the objectClass "Contact":
 Get-ADGroup -Identity SomeGroup -Properties Member | Select-Object -ExpandProperty Member | Get-ADObject | Where-Object {$_.ObjectClass -eq 'Contact'}

Open in new window

AlexA lack of information provides a lack of a decent solution.

Author

Commented:
Ahhhh

Makes sense now, I knew I needed to use the get-adobject but I couldn't figure out the best way, as always thank you for your help.


Thanks
Alex
AlexA lack of information provides a lack of a decent solution.

Author

Commented:
ACtually

oBdA, could you tell me how I can get it to reference the group that it's found the contact in??? I was wrong, we do have contacts in groups (it just came through)

I can then output it to a CSV

Thanks
Alex
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Get-ADGroup -Identity SomeGroup -Properties Member | ForEach-Object {
	$group = $_
	$_.Member |
		Get-ADObject |
		Where-Object {$_.ObjectClass -eq 'Contact'} |
		Select-Object -Property @{n='Group'; e={$group.Name}}, @{n='GroupDN'; e={$group.DistinguishedName}}, *
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial