I had a client ask me to create a mailbox creation script that would create new mailboxes on the smallest DB in the US.
After doing a bit of research and running into some issue with the Get-MailboxDatabase cmdlet returining 0 for the DatabaseSize property I came up with the following script.
# This script will return the smallest mailbox database, which can be useful when creating new mailboxes or re-distributing based on size # Created by Jason Sherry (izzy@izzy.org) 3/25/2012 # Last Updated: 6/16/2012 # Source: http://izzy.org/scripts/Exchange/Admin/Get-SmallestDB.ps1 # Partial code source: http://powershell.com/cs/media/p/3981.aspx $MBXDbs = Get-MailboxDatabase | Where-Object {$_.Identity -notlike "TCN-EU-*"} # This will exclude any DB that started with "TCN-EU-" # Loop through each of the MBXDbs ForEach ($MBXDB in $MBXDbs) { # Get current mailboxes sizes by summing the size of all mailboxes and "Deleted Items" in the database $TotalItemSize = Get-MailboxStatistics -Database $MBXDB | %{$_.TotalItemSize.Value.ToMB()} | Measure-Object -sum $TotalDeletedItemSize = Get-MailboxStatistics -Database $MBXDB.DistinguishedName | %{$_.TotalDeletedItemSize.Value.ToMB()} | Measure-Object -sum #Get-MailboxDatabase and the DatabaseSize property was not used since it does not return a value in some environments as of 2010 SP2 $TotalDBSize = $TotalItemSize.Sum + $TotalDeletedItemSize.Sum # Compare the sizes to find the smallest DB If (($TotalDBSize -lt $SmallestDBsize) -or ($SmallestDBsize -eq $null)) { $SmallestDBsize = $TotalDBSize $SmallestDB = $MBXDB } } Write-host "Smallest DB: " $SmallestDB
I use following
$mbxDB_smallest = Get-MailboxDatabase * -Status | sort -Property DatabaseSize | select -First 1
$mbxDB_smallest
LikeLike
There is an obvious error:
$SmallestDBsize = $DBsize
Right:
$SmallestDBsize = $TotalDBSize
LikeLiked by 1 person
Thanks, just fixed it above.
LikeLike