Getting users from dynamic distribution group Exchange 2007/2010
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
Related videos on Youtube
MadBoy
Updated on September 18, 2022Comments
-
MadBoy 9 monthsI'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:

The code to list:
$MarketingGroup = Get-DynamicDistributionGroup "Marketing Group" Get-Recipient -RecipientPreviewFilter $MarketingGroup.RecipientFilter -OrganizationalUnit $MarketingGroup.OrganizationalUnitSo I modified it a bit:
$members = Get-DynamicDistributionGroup -Identity "dynamic group" Get-Recipient -RecipientPreviewFilter $members.RecipientFilter -OrganizationalUnit $members.OrganizationalUnit | select Displayname,PrimarySmtpAddress > membersall.txtbut 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
Containerthe users are in (even thou$members.OrganizationalUnitshould do the trick). It seems to return everyone withUsers with Exchange mailboxesthat are in the chosen container but it also takes the people which are in defaultUsers OU.So how to modify the query to display only the ones within the recipient container chosen without the default Users OU.
-
Rajshree Gupta over 11 yearsWell when I run that here I get the proper listing scoped to the OU defined. Are you not getting that? I'm confused -
Rajshree Gupta over 11 yearsThe .OrganizationalUnit is the location of the dynamic distribution group, not the scope you defined in the group. -
MadBoy over 11 yearsI'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. -
Rajshree Gupta over 11 yearsI did just look on the MS page and they do have misinformation there.