Wednesday, 18 December 2024

Mailbox Count per DAG (Database Availability Group)

 

$Output = [system.collections.arraylist]@()
$Output.Clear()

$DAG = Get-DatabaseAvailabilityGroup

$DAG |ForEach-Object{

   $DiscoveryMailbox  = $null
   $RoomMailbox     =    $null
   $SharedMailbox     = $null
   $TeamMailbox     =    $null
   $UserMailbox       = $null
   $Total             = $null

   $AllMailbox = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Database -match $DagName}    
 
   [int]$DiscoveryMailbox  += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Discovery"}).Count)
   [int]$RoomMailbox      += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Room"}).Count)
   [int]$SharedMailbox     += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Shared"}).Count)           
   [int]$TeamMailbox      += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Team"}).Count)          
   [int]$UserMailbox       += [int](($allmailbox|?{$_.RecipientTypeDetails -match "User"}).Count)         
   [int]$Total             += [int]($allmailbox.Count)
 
   $Property=[pscustomobject]@{
       DAG               = "AIB"+ ($DagName.Replace("-","")).ToString()
       DiscoveryMailbox  = $DiscoveryMailbox
       RoomMailbox       = $RoomMailbox   
       SharedMailbox     = $SharedMailbox   
       TeamMailbox       = $TeamMailbox   
       UserMailbox       = $UserMailbox     
       Total             = $Total           
   }
   $Output.Add($Property)
}

 $Output | ft -AutoSize


--------------------------------- End --------------------------------- 

No comments:

Post a Comment