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.

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Answer accepted by question author
  1. Vasil Michev 124.4K Reputation points MVP Volunteer Moderator
    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. Anonymous
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.