Aug 29 2018 03:56 AM
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
Aug 29 2018 08:52 AM
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
Aug 29 2018 01:56 PM
You would need a script that cycles through all the distribution groups and members within them and list the groups that a particular member is a part of. I got this task back in the days. you can use this script to check if a user is a part of a distribution group.
https://gallery.technet.microsoft.com/scriptcenter/Get-Distribution-lists-2ceda593
Aug 29 2018 11:29 PM
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.
Aug 30 2018 12:19 AM - edited Aug 31 2018 05:52 AM
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*
Mar 26 2019 05:42 AM - edited Mar 26 2019 06:24 AM
@VasilMichevthe need for speed? try this...
Get-ADObject -LDAPFilter "(&(objectCategory=contact)(objectClass=contact)(memberOf=*))" -Properties Name,MemberOf,CanonicalName | ft Name,CanonicalName,memberof -wrap
Oct 10 2019 07:47 AM
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
Feb 04 2020 11:49 AM
I am working on the same ask. @Mark Louie Diaz
Did you find a resolution?
Sep 13 2022 04:39 AM
This works for me:
Get-ADObject -LDAPFilter '(&(objectclass=contact)(!(memberof=*)))' -Server dc01 -SearchBase 'OU=Contacts,OU=Company,DC=work,DC=com' -Properties name
Oct 21 2022 08:14 AM
Sep 12 2023 12:35 PM
Dec 28 2023 08:05 AM - edited Dec 28 2023 08:11 AM
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.