Forum Discussion
Mark Louie Diaz
Aug 29, 2018Copper Contributor
Get mailcontact if member of any group
Hi Tech Community, May I ask how can I accomplish the subject? I want to know before removing a mail contact if it is a member of a Distribution group. Best Regards, Mark
VasilMichev
Aug 30, 2018MVP
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.
Robert Bollinger
Oct 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