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
Adam Ochs
Aug 29, 2018Iron Contributor
Hey Mark Louie Diaz,
I think this would work:
$Username = "user@domain.com"
$DistributionGroups= Get-DistributionGroup | where { (Get-DistributionGroupMember $_.Name | foreach {$_.PrimarySmtpAddress}) -contains "$Username"}
Just toss in the email address for the mail user in there, and it should return any DL that has that user.
Adam