Forum Discussion

WaldoKing's avatar
WaldoKing
Copper Contributor
Jun 22, 2023

Dynamic Distibution group

Hi Everyone 

 

I have been struggling with this query for a year. While I feel it should be so simple. 

 

Need a dynamic all staff group.

Using the 'all exchange mailboxes' option; includes shared mailboxes, distribution groups,  and contacts which I do not want. 

 

Tried in azure, linking it to license codes, but hit too many dead ends. 

 

Powershell is the way... 

Found a promising route and as I was playing around with it, I found out it filtered nothing. 

 

Here is what I need: 
• Dynamic distribution group with all users in

• Exclude sharedmailboxes, distribution, security, contacts etc. 

• Exclude admin accounts sysadmin@***

 

Here is what I have: 

New-DynamicDistributionGroup -Name "o" -RecipientFilter {(`
>>     (RecipientType -eq 'UserMailbox') `
>>     -and (-not(RecipientType -eq 'MailContact')) `
>>     -and (-not(MemberOfGroup -eq 'CN=AllExclusion,OU=SG,DC=Example,DC=Local')) `
>>     -and (-not(MemberOfGroup -eq 'email address removed for privacy reasons')) `
>>     -and (-not(Name -like 'Sysadmin{*')) `
>>     -and (-not(Name -like 'CAS_{*')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')) `
>>     -and (-not(RecipientTypeDetailsValue -eq 'GuestMailUser'))`
>> )}
 
Drilled down and found no difference in users, using any of these codes: 
o1 - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox') -and (-not(DisplayName -like 'Archive{*'))}
o2  - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox')}
o3 - New-DynamicDistributionGroup -Name "o" -RecipientFilter {(RecipientType -eq 'UserMailbox')-and (-not(Name -like 'Archive{*'))}
 
This is how I get the results
Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup -Identity "o").RecipientFilter -Resultsize unlimited | Export-csv C:\o.csv
 
Please help. I feel pathetic, that such a straight forward request, is so complex and has taken so long. 
 
  • RecipientType of "UserMailbox" does include shared, room and so on mailboxes. RecipientTypeDetails is what you need to use instead. Here's a comparisson:

    [09:13:42][O365]# Get-Recipient -RecipientType UserMailbox | group RecipientTypeDetails -NoElement

    Count Name
    ----- ----
    16 SharedMailbox
    16 UserMailbox
    1 TeamMailbox
    4 RoomMailbox
    5 SchedulingMailbox
    2 DiscoveryMailbox
    1 EquipmentMailbox


    [09:14:00][O365]# Get-Recipient -RecipientTypeDetails UserMailbox | group RecipientTypeDetails -NoElement

    Count Name
    ----- ----
    16 UserMailbox
  • RecipientType of "UserMailbox" does include shared, room and so on mailboxes. RecipientTypeDetails is what you need to use instead. Here's a comparisson:

    [09:13:42][O365]# Get-Recipient -RecipientType UserMailbox | group RecipientTypeDetails -NoElement

    Count Name
    ----- ----
    16 SharedMailbox
    16 UserMailbox
    1 TeamMailbox
    4 RoomMailbox
    5 SchedulingMailbox
    2 DiscoveryMailbox
    1 EquipmentMailbox


    [09:14:00][O365]# Get-Recipient -RecipientTypeDetails UserMailbox | group RecipientTypeDetails -NoElement

    Count Name
    ----- ----
    16 UserMailbox

Resources