• A-Z
  • Directory
  • myUVM
  • Loading search...

notepad.exe

new-mailbox.ps1

Posted: August 30th, 2013 by David Towle-Hilt

A little while ago we decided to reorganize our mailbox databases. This new scheme no longer classifies users into department or employee type. We decided to move towards a balanced database structure to help keep all our edb files about the same size.

We are now using the following script to create a new mailbox within the smallest database with the most whitespace where the DB names are as follows.
DB01
DB02
DB03

If the DB name also ends with ‘ (Unlimited)’ than we will choose that for mailboxes that do not have limits.

# new-mailbox.ps1 -Identity [string] -Alias [string] -DisplayName [string] -Unlimited

param{
	[string]$Identity,
	[string]$Alias,
	[string]$DisplayName,
	[switch]$Unlimited
}

# get mailbox database statistics.
$dbs = Get-MailboxDatabase -Status | Select-Object @{E={$_.Identity};L="Name"},@{E={(Get-Item ("\\" + $_.MountedOnServer + "\" + ($_.EdbFilePath -replace ":","$"))).Length / 1048576};L="EdbFileSizeMB"},@{E={$_.AvailableNewMailboxSpace.ToMB()};L="EdbWhiteSpaceMB"} | Sort-Object -Property @{E="EdbFileSizeMB";D=$false},@{E="EdbWhiteSpaceMB";D=$true}

switch ($Unlimited) { 
	$true { $filter = "(Unlimited)" }
	default { $filter = "DB[0-9]{1,4}$" } 
}

# get the smallest database with the most whitespace
$db = ($dbs | ?{$_.Name -match $filter})[0].Name.Name

Enable-Mailbox -Identity "DOMAIN\$identity" -Alias $alias -Database $db -DisplayName $displayname

Set-Mailbox -EmailAddresses @{add=($identity + "@domain.com")}
Contact Us ©2010 The University of Vermont – Burlington, VT 05405 – (802) 656-3131