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.
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*