Exclude hidden mailboxes from a Dynamic Distribution Group

Another interesting finding I made thanks to an Expert Exchange question I was involved with.

The question sounded pretty simply

I can create new dynamic distribution groups using powershell and the Exchange Console, but I cannot figure out how to filter the hidden mailboxes so they are not added.

I logically started by trying to use the msExchHideFromAddressLists attribute trying to get the list of mailboxes where it is set to false using the following powershell script to create the Dynamic Distribution List

New-DynamicDistributionGroup -Name "test" -OrganizationalUnit 'mydomain/Distribution Groups' -RecipientContainer mydomain -RecipientFilter { recipienttype -eq 'usermailbox' -and HiddenfromAddresslistsEnabled -eq $false}

But I was surprised to noticed it didn’t work! It was actually returning only mailboxes the ones hidden from the address lists. There was something wrong in my OPATH query but wasn’t able to find out what up front…

To double check I was not missing something I tried creating another DDG with the same command as above just with HiddenfromAddresslistsEnabled -eq $true and both groups where giving exactly the same results! Here is the full powershell command I used to create test1

New-DynamicDistributionGroup -Name "test1" -OrganizationalUnit 'mydomain/Distribution Groups' -RecipientContainer mydomain -RecipientFilter { recipienttype -eq 'usermailbox' -and HiddenfromAddresslistsEnabled -eq $true}

That was pretty weird !

I decided next to give it another approach and I replaced HiddenfromAddresslistsEnabled -eq $false by HiddenfromAddresslistsEnabled -ne $true.

For all practical purposes the above 2 statements are exactly the same since HiddenfromAddresslistsEnabled is a Boolean attribute but for a mysterious reason Exchange responded perfectly to that one and returned only mailboxes that are not hidden from the address lists!

New-DynamicDistributionGroup -Name "test2" -OrganizationalUnit 'mydomain/Distribution Groups' -RecipientContainer mydomain -RecipientFilter { recipienttype -eq 'usermailbox' -and HiddenfromAddresslistsEnabled -ne $true}

A final test I tried was yet another variation of the powershell command using the -not(HiddenfromAddresslistsEnabled -eq $true) this time and here again Exchange returned the correct user mailboxes

New-DynamicDistributionGroup -Name "test3" -OrganizationalUnit 'mydomain/Distribution Groups' -RecipientContainer mydomain -RecipientFilter { recipienttype -eq 'usermailbox' -and -not(HiddenfromAddresslistsEnabled -eq $true)}

Guess it is just another Exchange 2007 mystery revealed…

I have been working in IT consultancy and solution integration since 1998 and I consider myself lucky to be, one in a few, making a living out of my passion. I am also member of the famous Experts Exchange (profile here) online community where I try my best to share what I have learned along the road.

Posted in Messaging & Collaboration Tagged with: , , , ,
2 comments on “Exclude hidden mailboxes from a Dynamic Distribution Group
  1. Fred M. says:

    Thanks for sharing ! worked like a charm

  2. sleepy says:

    The thing is there are 3 possible values for msExchHideFromAddressLists:
    TRUE
    FALSE
    <not set=””>
    Most users, in my case at least, have msExchHideFromAddressLists = <not set=””>, so they won't show up if you use HiddenfromAddresslistsEnabled -eq $false</not></not>

Leave a Reply

Your email address will not be published. Required fields are marked *

*