Search code examples
.netpowershellscriptingwindow

How to get the Exchange servers of DBs having activation preference 1 in powershell


I need to get only activation preference 1 of specific server in powershell.

Under the below command I can get the list of DB with their activation preference.

I need the DBs of EXSVR01 having activation preference 1 alone.

    Get-MailboxDatabase -Server EXSRV01 | sort name | ft name, server, activationpreference -a

Name                  ActivationPreference
----                  --------------------
DB01 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB02 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB03 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB04 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}
DB05 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB06 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB07 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB08 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}
DB09 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB10 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB11 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB12 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}
DB13 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB14 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB15 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB16 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}
DB17 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB18 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB19 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB20 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}
DB21 {[EXVR01, 1], [EXVR02, 2], [EXVR03, 3], [EXVR04, 4]}
DB22 {[EXVR02, 1], [EXVR01, 2], [EXVR04, 3], [EXVR03, 4]}
DB23 {[EXVR03, 1], [EXVR04, 2], [EXVR01, 3], [EXVR02, 4]}
DB24 {[EXVR04, 1], [EXVR03, 2], [EXVR02, 3], [EXVR01, 4]}

on example above

EXSVR01 has DB01, DB05, DB09, DB13, DB17, DB21


Solution

  • The following snippet works on my environment what's Windows Server 2019 Core with Exchange Server 2019 (Version 15.2 (Build 397.3)):

    Get-MailboxDatabase -Server 'EXSRV01' | 
        Select-Object name, server -ExpandProperty activationpreference | 
            Where-Object {$_.Key -eq 'EXSRV01' -and $_.Value -eq 1}