none
get distribution group of all mailboxes RRS feed

  • Question

  • Hello All,since we do not have a direct exchange powershel  cmdlet to get distribution groups of a user, we get all distribution groups, get members of each group and then compare if my mailbox is part of this user's list, i take that group.

    But this is very very costly and in-efficient way of doing :(

    So i am planning to use AD cmdlet Get-ADUser which has the 'memberOf' property which can get me directly my mailbox's distribution group membership.

    I have to do this in the manged code in c#.

    Is there any easier way to do this? Using only exchange powershell cmdlet ?

    pls help. Thanks.


    /M

    Monday, April 1, 2013 12:16 PM

All replies

  • Hi,

    In powershell, u can get the distribution groups of one mailbox using this one liner:

    Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "user@domain.com" } 

    where user@domain.com is the primary email address of your target mailbox. You can loop over all mailboxes, and replace user@domain.com with email address of each user.

    Please also look at this thread

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com

    Friday, April 5, 2013 9:57 PM
  • I agree this is just a one liner - but a very very costly and in-efficient way. This is the way I do not want to do. Here for each mailbox I have, I will get all distribution groups and members of each distribution  group and compare my mailbox with each member..!!! This is a very costly operation..!!!

    /M

    Saturday, April 6, 2013 2:51 AM
  • Why don't you just use LDAP directly eg use the System.DirectoryServices.AccountManagement classes in .net 3.51 see  http://msdn.microsoft.com/en-us/magazine/cc135979.aspx. (look at the GetGroups() and GetAuthorizationGroups() methods)

    Cheers
    Glen

    Monday, April 8, 2013 4:35 AM
  • Hi,

    Yes, but returned groups may or may not be Exchange Distribution Groups. If we assume that an Exchange Distribution Group would not have empty value in "mail" property, then can put a check on that property after calling GetGroups() or GetAuthorizationGroups() method.




    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com

    Monday, April 8, 2013 1:03 PM
  • get-group -filter 'Members -eq "<user_dn>"'
     is the way to go :(

    sad for so many days I could not find it :(

    I should read all exchange cmdlets some 1000 times....

    thanks for all the inputs..


    /M

    Monday, April 8, 2013 6:03 PM
  • Did you ever find a more efficient way of doing this???

    /sRc

    Tuesday, January 7, 2014 7:16 AM
  • Hi sRc

    get-group -filter 'Members -eq "<user_dn>"'

    is the best and efficient way. There is no performance issues at all and all my customers are happy :)


    /M

    Tuesday, January 7, 2014 7:29 AM
  • I was hoping to find a way to list all mailboxes and list the DL they are in without rerunning ths script after changing it for every user. (for each....) I am not the best at ps and have been stuck on this for a few days...

    Thanks,

    /sRc

    Tuesday, January 7, 2014 7:48 AM