Dynamic distribution list remove shared mailboxes

Stephen Schauble 20 Reputation points
2024-09-20T16:20:16.8566667+00:00

I have a DDL for allstaff set up that anyone that has any user with exchange mailbox. I would like to remove shared email boxes. I have seen a lot of PS commands although none of them seem to work. I am probably missing something very simple as I am not a good power shell user. I am basically a copy paste guy. Would anyone be able to help me with that final command

I have gotten up to

Get-Recipient -Filter (Get-DynamicDistributionGroup "allstaff").RecipientFilter

and that shows me the DDL

although this one throws off all types of errors
Set-DynamicDistributionGroup -identity {$DistroIdentity} -RecipientFilter {(-not(RecipientTypeDetailsValue -eq SharedMailbox)) -and (-not(RecipientTypeDetailsValue -eq RoomMailbox)) -and (-not(RecipientType -eq MailContact)) -and (-not(RecipientType -eq MailUniversalDistributionGroup)) -and (-not(RecipientTypeDetailsValue -eq EquipmentMailbox))}

I am assuming I am missing something simple but have no idea what that is.... If anyone wants to help me out I would appreciate it.

Microsoft Exchange Online
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,552 questions
{count} votes

Accepted answer
  1. Vasil Michev 106.6K Reputation points MVP
    2024-09-20T17:00:58.0433333+00:00

    You're simply missing the quotes, i.e. use

    (-not(RecipientTypeDetailsValue -eq "RoomMailbox"))
    

    instead of

    (-not(RecipientTypeDetailsValue -eq RoomMailbox))
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bruce Jing-MSFT 5,255 Reputation points Microsoft Vendor
    2024-09-23T02:21:40.9133333+00:00

    Hi,@Stephen Schauble

    Thanks for posting your question in the Microsoft Q&A forum.

    I'm glad your problem was resolved, please let me summarise the cause of the error.

    When using PowerShell commands, variables following parameters need to be in quotes.

    User's image


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.