0

I've found article at Microsoft claiming that this powershell query would give me a list of users in a dynamic distribution group that is defined more or less like this:

Image

The code to list:

$MarketingGroup = Get-DynamicDistributionGroup "Marketing Group"
Get-Recipient -RecipientPreviewFilter $MarketingGroup.RecipientFilter -OrganizationalUnit $MarketingGroup.OrganizationalUnit

So I modified it a bit:

$members = Get-DynamicDistributionGroup -Identity "dynamic group"
Get-Recipient -RecipientPreviewFilter $members.RecipientFilter -OrganizationalUnit $members.OrganizationalUnit | select Displayname,PrimarySmtpAddress > membersall.txt

but the problem is my query (and Microsoft for that matter) takes only part of equation into consideration. It takes the radio/checkboxes choice but it seems to be skipping the Container the users are in (even thou $members.OrganizationalUnit should do the trick). It seems to return everyone with Users with Exchange mailboxes that are in the chosen container but it also takes the people which are in default Users OU.

So how to modify the query to display only the ones within the recipient container chosen without the default Users OU.

MadBoy
  • 3,725
  • 15
  • 63
  • 94

2 Answers2

3

You are using the wrong property for OrganizationalUnit The following should work:

$MarketingGroup = Get-DynamicDistributionGroup "Marketing Group"
Get-Recipient -RecipientPreviewFilter $MarketingGroup.RecipientFilter -OrganizationalUnit $MarketingGroup.RecipientContainer
Nate
  • 3,378
  • 15
  • 21
  • That's what they proposed on Microsoft website :) I'm having hard time "finding" the right keywords myself. – MadBoy Mar 16 '12 at 17:41
  • Well when I run that here I get the proper listing scoped to the OU defined. Are you not getting that? I'm confused – Nate Mar 16 '12 at 18:00
  • The .OrganizationalUnit is the location of the dynamic distribution group, not the scope you defined in the group. – Nate Mar 16 '12 at 18:02
  • I'm sure it will work. I'm just saying Microsoft website is wrong and that I knew i have to change the OrganizationalUnit to something and I didn't knew to what. I miss the autocomplete from Visual Studio/Resharper for this kind of thing. – MadBoy Mar 16 '12 at 18:02
  • I did just look on the MS page and they do have misinformation there. – Nate Mar 16 '12 at 18:04
0

Incase your Dynamic DL was made in Exchange 2003 or prior... or you're running a hybrid environment. Give this one-liner a crack. Note the difference is using the LDAPRecipientFilter instead of just RecipientFilter. In a 2003 environment, the plain RecipientFilter value will be null.

Get-Recipient -RecipientPReviewFilter (Get-DynamicDistributionGroup -Identity *groupname*).LDAPRecipientFilter | Select Name,PrimarySMTPAddress
Thranx
  • 1