Loadbalance of the Exchange Database is very important. We need to make sure that database is not dumped with all the mailbox and once database gets big then move maiboxes to the other database. We can automate this process buy make the script to find the smallest size of the database in the Exchange orginisation and create the mailbox in the same
$MailboxSvr = Get-MailboxServer | select name
$i = 0
foreach($svr in $mailboxsvr)
{
$db = Get-MailboxDatabase -Server $svr.Name
foreach($database in $db)
{
$Server = $database.Server.Name
$Db = $database.Identity
$edbfilepath = $database.EdbFilePath
$path = “`\`\” + $Server + “`\” + $edbfilepath.DriveName.Remove(1) + “$”+ $edbfilepath.PathName.Remove(0,2)
$Dbsize = get-item $path |select-object length
$K = $Server + ” ” + $Db + ” ” + $Dbsize.Length
if ($i -eq 0 )
{
$edbsize = $Dbsize.Length
}
If ($edbsize -gt $Dbsize.Length)
{
$edbsize = $Dbsize.Length
$sdb = $database.Identity
}
$i = 1
}
}
Write-output “ENTER THE FOLLOWING DETAILS”
$DName = Read-Host “User Diplay Name ”
$FName = Read-Host “First Name ”
$LName = Read-Host “Last Name ”
$passwd = Read-Host “Password ” -asSecureString
$PrincipalName = $FName + “.” + $LName + “@domain.com”
$Aliasname = $FName + “.” + $LName
New-Mailbox -Name $DName -Database $sdb -UserPrincipalName $PrincipalName -FirstName $FName -LastName $LName -Alias $Aliasname -Password $passwd -ResetPasswordOnNextLogon $true -SamAccountName $Aliasname
You can get the complete copy of the code in the below link file