April 28, 2009

Load Balancing Exchange 2007 Mailbox databases (UMRA)

Posted in Exchange 2007 at 8:51 pm by Sean Burke

I was recently tasked with building an automated user account management system that required creating Exchange 2007 mailboxes.  The client required that the mailbox database load be balanced by creating the new mailbox in the smallest database on a given server/storage group.    This solution is based on a powershell script originally written by Ben Lye in 2008 and then modified and “XMLized” for import into UMRA by myself and Allan Bogh.  This XML file is ready to be imported directly into UMRA’s dynamic actions folder.  Once imported, You will find a new script action under the Exchange 2007 category in the UMRA console called “Get Smallest Mailbox database”.  This action expects the name of an exchange 2007 server and will return the full path (servername\storage group\databasename) of the smallest mailbox database on that server.  This output is suitable for use directly in the “Create(Enable) mailbox (Exchange 2007)” script action.  Be sure to save the file as “UNICODE” else there will be problems with importing it into UMRA.

Here is the xml file:

<?xml version=”1.0″ encoding=”utf-16″?>
<UmraDynamicAction version=”1″ type=”Powershell”>
<General>
<Name>Get Smallest Mailbox Database (Exchange 2007)</Name>
<Description>Retrieve the smallest mailbox database object from a server. The action returns the path to the smallest mailbox database.</Description>
<ActionTreeLabels>Exchange, Exchange 2007, Exchange server</ActionTreeLabels>
<ActionTreePosition>12000</ActionTreePosition>
<ActionImage>55</ActionImage>
<HelpId>28</HelpId>
<Version>561</Version>
</General>
<Configuration>
<PowershellSnapIn>Microsoft.Exchange.Management.PowerShell.Admin</PowershellSnapIn>
</Configuration>
<ActionProperties>
<ActionProperty>
<DisplayName>Server</DisplayName>
<Name>Server</Name>
<Description>Required value. The Server parameter specifies the name of the server from which to retrieve mailbox database information.</Description>
<ValueType>Text</ValueType>
<Direction>in</Direction>
<Mandatory>Yes</Mandatory>
<MandatoryProps/>
<MandatoryAbsentProps/>
</ActionProperty>
<ActionProperty>
<DisplayName>Database</DisplayName>
<Name>Database</Name>
<Description>The result (Full path to database).</Description>
<ValueType>Text</ValueType>
<Direction>Out</Direction>
<OutputVariable>%Database%</OutputVariable>
<Mandatory>No</Mandatory>
<MandatoryProps></MandatoryProps>
<MandatoryAbsentProps></MandatoryAbsentProps>
<ReturnData>
<PowershellVariable type=”value”>Database</PowershellVariable>
</ReturnData>
</ActionProperty>
</ActionProperties>
<Script>
<ScriptPhrase>
<ActionProperty>
<Name>Server</Name>
<Condition Criterion=”IfNotEmptyOnly”/>
<Replacement>%Server%</Replacement>
</ActionProperty>
<Contents>
# Script to return the smallest database on a specified server
# Written by Ben Lye – 20th August 2008
# Modified by Allan Bogh (Advanced Toolware LLC) and keyboard monkey Sean Burke
$databases = Get-MailboxDatabase -Server %Server% -ErrorAction SilentlyContinue
# Error if there are no databases found
If (-not $databases) {
Write-Host “Error: No databases found for server $server” -ForegroundColor “Red”
Write-Host
$break
}
If ($databases) {
# Prepare some variables for storing the name and size of the smallest database
$smallestdbsize = $null
$smallestdb = $null
# Loop through each of the databases
Foreach ($database in $databases) {
# Get the size of the .edb file
$dbsize = (get-childitem (“\\” + $database.Server + “\” + $database.EDBFilePath.PathName -replace(“:”,”$”)) | select-object name,length).length
# Compare the sizes to find the smallest DB
if (($dbsize -lt $smallestdbsize) -or ($smallestdbsize -eq $null)) {
$smallestdbsize = $dbsize
$Database=($database.Server.Name) + “\” + ($database.StorageGroup.Name) + “\” + ($database.Name)
}
}
}

</Contents>
</ScriptPhrase>
</Script>
</UmraDynamicAction>

April 27, 2009

UMRA Project Development

Posted in Automation tagged at 10:53 pm by Sean Burke

This is a test post