How do get this command to return the results I need

cdsrm43 0 Reputation points
2025-01-03T15:34:09.4+00:00

First and foremost I am not a programmer, so scripting is hard for me. I have been tasked with creating dynamic distribution lists, while there is a GUI option in AAD it is not allowing for the granularity that we are seeking. We need the list to not include shared mailboxes, resource rooms, and other groups. I have tried several different things and I can get close but all the way there.

I used this command to create the ddg - New-DynamicDistributionGroup -Name "XXXX-ALL" -RecipientFilter "(RecipientTypeDetails -eq 'UserMailbox') -and (RecipientTypeDetails -eq 'UserMailbox')"

Then ran this -

Set-DynamicDistributionGroup 'XXXX-All Employees'-RecipientFilter {(-not(RecipientTypeDetailsValue

-eq 'SharedMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'RoomMailbox')) -and (-not(RecipientType -eq 'MailContact')) -and (-not(RecipientType -eq 'MailUniversalDistributionGroup')) -and (-not(RecipientTypeDetailsValue -eq 'EquipmentM

ailbox')) -and (-not(RecipientType -eq 'MailUniversalSecurityGroup')) -and (-not(CustomAttribute1 -eq 'shared')) -and (-not(Company -eq 'Property')) -and (-not(GroupType -eq 'Universal')) -and (-not(GroupType -eq 'BuiltinLocal')) -and (-not(GroupType -eq 'Global')) -and (-not(GroupType -eq 'DomainLocal')) -and (-not(RecipientTypeDetails -eq 'MailUser')) -and(-not(RecipientTypeDetails -eq 'DynamicDistributionGroup')) -and (-not(RecipientTypeDetails -eq 'MailContact')) -and (-not(RecipientTypeDetails -eq 'MailContact')) -and (-not(RecipientTypeDetails -eq 'MailUniversalSecurityGroup')) -and (-not(RecipientTypeDetails -eq 'MailUniversalDistributionGroup')) -and (-not(RecipientTypeDetails -eq 'GroupMailbox')) -and

(-not(RecipientTypeDetails -eq 'TeamMailbox'))}

I was still getting inconsistent results so I created another -

New-DynamicDistributionGroup -Name Test122024 -IncludedRecipients "MailboxUsers" -ConditionalCompany "XXXX"

But that version adds resource room accounts so I ran this - Set-DynamicDistributionGroup -Identity test122024 -RecipientFilter "ExtensionCustomAttribute3 -ne 'Room'"

That added in a bunch of groups that I did not need. Super lost, really need an assist.

FWIW - have tried using both single and double quotes for most of these and that has not changed the output.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,598 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,723 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,496 Reputation points
    2025-01-03T20:20:48.6033333+00:00

    The question would probably benefit from adding an appropriate Exchange tag.

    It would seem to me that you'd only need the recipient filter to include the test for "RecipientTypeDetails -eq 'UserMailbox'". But my experience with Exchange has been exclusively with on-prem organizations, not with O365.

    If it's any help, I think these are the sets of values for RecipientType and RecipientTypeDetails. Although you included "RecipientTypeDetailsValue" in your example, I'm not sure what those are!

    # RecipientType
    # UserMailbox: A standard mailbox for an individual user.
    # SharedMailbox: A mailbox that multiple users can access and send emails from.
    # RoomMailbox: A mailbox assigned to a meeting location, such as a conference room.
    # EquipmentMailbox: A mailbox assigned to a piece of equipment, like a projector.
    # MailContact: A mail-enabled contact that contains information about people or organizations outside your Exchange organization.
    # MailUser: A mail-enabled user that has an external email address.
    # MailUniversalDistributionGroup: A mail-enabled distribution group.
    # MailUniversalSecurityGroup: A mail-enabled security group.
    # DynamicDistributionGroup: A distribution group with membership based on specific criteria.
    # RemoteUserMailbox: A mailbox for a user that is hosted in a different Exchange organization.
    # RemoteRoomMailbox: A room mailbox that is hosted in a different Exchange organization.
    # RemoteEquipmentMailbox: An equipment mailbox that is hosted in a different Exchange organization.
    # RemoteSharedMailbox: A shared mailbox that is hosted in a different Exchange organization.
    # LinkedMailbox: A mailbox that is associated with an account in a different forest.
    # LegacyMailbox: A mailbox that is hosted on an older version of Exchange.
    # PublicFolder: A mail-enabled public folder.
    # PublicFolderMailbox: A mailbox that hosts public folders.
    # MailboxPlan: A template for creating mailboxes with specific settings.
    # DiscoveryMailbox: A mailbox used for eDiscovery purposes.
    # ArbitrationMailbox: A mailbox used for managing approval workflows.
    # AuditLogMailbox: A mailbox used for storing audit logs.
    # ArchiveMailbox: A mailbox used for archiving emails.
    
    # RecipientTypeDetails
    # UserMailbox: 1
    # LinkedMailbox: 2
    # SharedMailbox: 4
    # LegacyMailbox: 8
    # RoomMailbox: 16
    # EquipmentMailbox: 32
    # MailContact: 64
    # MailUser: 128
    # MailUniversalDistributionGroup: 256
    # MailNonUniversalGroup: 512
    # DynamicDistributionGroup: 1024
    # PublicFolder: 2048
    # SystemAttendantMailbox: 4096
    # SystemMailbox: 8192
    # MailForestContact: 16384
    # MailForestUser: 32768
    # RemoteUserMailbox: 2147483648
    # RemoteRoomMailbox: 8589934592
    # RemoteEquipmentMailbox: 17179869184
    # RemoteSharedMailbox: 34359738368
    # PublicFolderMailbox: 68719476736
    # ArbitrationMailbox: 137438953472
    # MailboxPlan: 274877906944
    # AuditLogMailbox: 549755813888
    # RemoteTeamMailbox: 1099511627776
    # TeamMailbox: 2199023255552
    # SharedMailbox: 4398046511104
    # GroupMailbox: 8796093022208
    # DiscoveryMailbox: 17592186044416
    # GuestMailUser: 35184372088832
    # RemoteGroupMailbox: 70368744177664
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.