Stumbled upon an old post which announced the winner of an Exchange 2007 scripting contest. The winning entry was a one-liner.

(Get-MailboxDatabase | foreach { get-childitem $_.edbFilePath | select-object name,length} | sort -property length)[0]

Description: Locates the smallest mailbox database (in terms of size) for automatic provisioning process. The script retrieves a collection of mailbox databases, finds the size of each database, sorts the list based upon length, then returns the name of the smallest database.

In comments, Nick provides another script.

If you want to provision mailboxes based upon mailbox count in a database you can easily get the information with the following script: (This will run slower)

Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database | Sort-Object -Property:Count

In any similar command, you can add parenthesis and the number of values you need in square brackets – like (command)[1] no space between the brackets – to look at only top/bottom values.

E.g. (Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database | Sort-Object -Property:Count)[0,1]

More scripts can be found at Microsoft TechNet Script Center

-Thanks, Jinesh.