Excluding Resource Mailboxes (e.g. rooms) from Dynamic Distribution Groups in Office365

I hadn’t noticed until today that rooms are included in Office365 dynamic groups even if you selected “Users with Exchange mailboxes”. This creates an interesting effect if you send an appointment to that group, you will automatically book all your meeting rooms as well. Not necessarily what you want.

Dynamic Group Example

The solution is fairly straightforward. Via PowerShell, you add a specific filter for MailboxType as follows. Warning: you can’t edit the members filter from the Exchange Admin Center (EAC) anymore after applying this filter.

# Connect to Office365
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

# Add the filter
Set-DynamicDistributionGroup -Identity "[email protected]" -RecipientFilter {(RecipientTypeDetails -eq 'UserMailbox')}

# Test the filter works by enumerating the members
$FTE = Get-DynamicDistributionGroup "[email protected]"
Get-Recipient -RecipientPreviewFilter $FTE.RecipientFilter