This function retrieves the total size (in GB) of mailbox databases in Exchange Organization. There is an optional parameter to filter databases by part of name. When you specify a value for the Name attribute and no databases could be found, it retrieves 0.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Function Get-MailboxDatabaseTotalSize {
param ([Parameter(Mandatory=$false, ValueFromPipeline=$false)][string]$DBPartName)
$Databases = Get-MailboxDatabase -Status | Where-Object {$_.Name -ilike '*'+$DBPartName+'*'}
foreach($Database in $Databases) {
$RawDBSize = $Database.DatabaseSize
$CounterDBTotalSize = $RawDBSize + $CounterDBTotalSize
}
try {
$CounterDBTotalSize = "{0:n2}" -f ($CounterDBTotalSize.ToBytes() / 1GB)
}
catch {
Write-Host "0"
}
Return $CounterDBTotalSize
} |

