Forum Discussion
Get mailcontact if member of any group
Here's a fast way to do it:
$dn = (Get-MailContact your_mail_contact).DistinguishedName
Get-Recipient -Filter "Members -eq '$dn'"
This will return all DGs, mail-enabled SGs and O365 Groups the contact might be a member of. And since it's a server-side filter, you don't need to iterate over each group.
- Joshua BinesMar 26, 2019Iron Contributor
VasilMichevthe need for speed? try this...
Get-ADObject -LDAPFilter "(&(objectCategory=contact)(objectClass=contact)(memberOf=*))" -Properties Name,MemberOf,CanonicalName | ft Name,CanonicalName,memberof -wrap
- ZK4568746Oct 21, 2022Copper ContributorUtilizing the LDAP FIlter was smart, it allowed me to act against just the ADObjects that were Contacts with existing group memberships without rewriting the entire script. Thanks!
- AshifsaifiSep 12, 2023Copper ContributorWorked for me.. it was really fast!! Can you please let me know how can I get primarysmtp address of contact via above script?
- JeanneSophiaDec 28, 2023Copper Contributor
This is much more efficient, I was needing members for contacts, we have huge environment so 40k of distribution lists would not be efficient to query,
I modified so
$c = get-contact (contact smtp)
Get-ADObject -Identity $c.DistinguishedName -Properties memberof |fl
and members resulted ***THANK YOU*** not sure why MS decided not to list "member of" in ECP / powershell for contacts.
- --ZiM-- .Aug 30, 2018Copper Contributor
The following will get you a cleaner list with all mailboxes followed by contacts $m = New-Object System.Collections.ArrayList $c = New-Object System.Collections.ArrayList Get-DistributionGroupMember GroupName | ForEach-Object { if($_.RecipientType.ToString().Contains("Mailbox") -eq $true) { $m.Add($_.Name) } else { if ($_.RecipientType.ToString().Contains( "Contact") -eq $true) { $c.Add($_.Name) } } } $m | Get-Mailbox | ft Name,For* $c | Get-MailContact | ft Name,For*
- Robert BollingerOct 10, 2019Iron Contributor
Hey Vasil,
On this here:
$dn = (Get-MailContact your_mail_contact).DistinguishedName
Get-Recipient -Filter "Members -eq '$dn'"
How would i add an input file to your script? for instance i would like to run the above cmdlets on a list of 122 people.
Thanks,
Robert