0

The end-game here is to create dynamic distribution groups based on similar Exchange databases. We have personnel mailboxes split into several databases by region and naming follows set conventions.

As a proof of concept I've been using the "Get-Mailbox" command with a -Filter and -or operators to list multiple databases and it works. The result is something like this:

Get-Mailbox -Filter {
(
(Database -eq 'CN=DBname01,CN=therestoftheDistinguishedName,DC=com') 
-or 
(Database -eq 'CN=DBname02,CN=therestoftheDistinguishedName,DC=com')
)
}

This works fine... I get a list of mailboxes in those databases. But isn't ideal if another database is added due to an increased user count.

MS documentation here says that the "homeMDB/Database property is compatible with wildcards...

So, this should then theoretically work and give the same result:

Get-Mailbox -Filter {(Database -like "CN=DBname*")}

But, this command returns no results.... no errors... nothing.

Is -like just not supported? Am I doing something wrong?

P.S. '-Filter' will be replaced with '-RecipientFilter" for the New-DynamicDistributionGroup command. Get-Mailbox is being used to verify that my filter is working correctly.

shimojimatto
  • 101
  • 1
  • 2
  • Try simply Get-Recipient -Database 'DBname*' – Vadim Oct 23 '18 at 11:51
  • `Get-Mailbox -Filter {Database -like 'CN=DBname*'}` (use apostrophes instead of double quotes; possibly remove `()` parentheses. – JosefZ Oct 23 '18 at 12:28
  • @Vadim That doesn't work because the Database parameter expects only one database – Joseph Oct 25 '18 at 09:25
  • What are you actually trying to accomplish here? What is the use case for a distribution group based on the database where the mailbox is hosted (which should be a technical detail of no interest to any user)? – Massimo Jun 05 '21 at 23:26

2 Answers2

0

Try this command:

get-mailbox |where{$_.database -like 'DBname*'}|ft name,database
Niko.Cheng
  • 511
  • 2
  • 4
  • He needs to use the Filter parameter specifically because he will use that filter later for a dynamic distribution group. – Joseph Oct 25 '18 at 09:25
0

Since you are going to use the RecipientFilter parameter for the New-DynamicDistributionGroup, I can see why you posed the question.

I can get it work with attributes other than "database". See below:

New-DynamicDistributionGroup "Test Group G" -RecipientFilter {DisplayName -like "G*"} -OrganizationalUnit $OU
$vargroup = Get-DynamicDistributionGroup "Test Group G"
Get-Recipient -RecipientPreviewFilter $varGroup.RecipientFilter

Returns a list of mail users (boxes, contacts, etc.) that are included in the new group. But when you run it with RecipientFilter parameter of {Database -like "partialDBname*"}, the same commands above return nothing also, much like Get-mailbox -Filter {Database -eq "DBname"} returns nothing. You may have to do it on something other than the database attribute. When you look at the Filter parameter on the Get-Mailbox cmdlet TechNet page, it actually points to the same "Filterable properties" page you referenced.

Edit: It looks like this is a thing. It's an old MS blog, but I haven't seen anything updated about this for future versions of Exchange. It looks like filtering on databases isn't possible. You could use other attributes though. You mentioned they are in different regions. You could use group policy to add/replace attributes to user objects.

I would create test groups and use the commands above to make sure I got the results I wanted.

Joseph
  • 208
  • 2
  • 10