Writing Exchange 2007 scripts does more than just save Nick time!

Published Feb 21 2007 04:52 PM 884 Views

The Exchange 2007 scripting contest has concluded and a winner has been selected. Congratulations to Nick Smith of Colorado State University on his winning entry: "Return the smallest database"!

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.

Script Code

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

The judges agreed that this is a great example of the versatility and power you can get by combining a variety of Exchange management shell cmdlets together with the built-in PowerShell cmdlets as a "one-liner". And the judges also agreed that next time we'll do better about announcing the winning entry in a more timely fashion – sorry for the long wait on the winning result to all who entered the scripting contest!

For his winning entry, Nick has won a trip to next Monday's "Ready for a New Day" Launch event in Seattle, WA that is highlighted by a keynote from Bill Gates: http://www.launchtour2007.com/PreReg/event.aspx?eventid=350.

Thanks to all who entered, and keep writing those PowerShell scripts and one-liners!

- Evan Dodds

Not applicable
Yes, this script does a fine job of selecting the smallest EDB, not the database with the least amount of mail and/or mailboxes.  This would work well if you do not have quotas and your whitespace is small.

For those of you that may want to use this script, remember that a provisioning system would want to know the MB store with the most space and would not care if the EDB is large with a lot of white space.  In that scenario it would be better to do a running sum on the mailbox quota for each mailbox in the MB store and use that sum as your comparison value.  It can be simplified more if all mailboxes in a store have the same quota; then it is mailbox count times quota.
Not applicable

You are correct.  This script is useful if your databases contain a small amount of whitespace.  In my case, I was performing mailbox migrations so my whitespace amount was minimal.  There is also the caveat that the script must be run locally on the Exchange server hosting the mailbox databases.

If you want to provision mailboxes based upon mailbox count in a database you can easily get the information with the following script:

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

This will give you a table of the count of mailboxes in each database.  If you want just the name of the database with the least mailbox count you can use:

(Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database | Sort-Object -Property:Count | Select-Object -Property:Name)[0]

Please be aware that this script is not as quick as finding the smallest database in terms of size.
Not applicable
So, where can we download all the entries?  I'd love to see all the runners up!!
Not applicable
Not applicable
Hi guys,

I can't seem to find where the OWA text strings are stored...  I am hoping to edit the text string on the OWA logon page that says "Principal Name" to something my users will recognize...  Any idea on where I can find that value to edit it?

Not applicable

OWA customization is something that we are working on for a future release, hopefully we will have something on it later this year. The only thing that we have now is this:


But I don't think it covers what you need.
Not applicable
Exchange 2007 Discontinued Features The 10 most common Exchange Server issues and how to avoid them Exchange
Not applicable
Can this be used even with Exchange 2003 mailboxes?
Not applicable

I've been looking for a while the way to contact you, but I can't fint it. Well I need your help, actually I'm using PowerShell with the purpose to create directly an exchange & AD account. With the PowerShell commands work fine. But I need to implement this in an ASP .NET application, this one is executed in the PDC machine, but I receive this error:

Event Type: Error
Event Source: MSExchange ADAccess
Event Category: General
Event ID: 2152
Date: 26/03/2007
Time: 17:12:06
User: N/A
Computer: MOSS
Process PortalAccountCleaner.exe (PID=5816). An remote procedure call (RPC) request to the Microsoft Exchange Active Directory Topology service failed with error 1753 (Error 6d9 from HrGetServersForRole). Make sure that the Remote Procedure Call (RPC) service is running. In addition, make sure that the network ports that are used by RPC are not blocked by a firewall.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

The application uses the System.Management.Automation, the core of the PowerShell, in order to try to create de user account, please I need help...

My name is Paúl Beltrán Naranjo
My mail is pbeltran79@yahoo.com

I live in Ecuador, thanks for your help.
Not applicable
Looking at this made me wonder if there is a way to build and exception handling into the move-mailbox command such as if my datastore is at 140gb user the next one
Version history
Last update:
‎Jul 01 2019 03:25 PM
Updated by: