- danovich.com.au -

For the enterprise sys admin by the enterprise sys admin

  • Home
  • About
  • Contact
  • RSS Feed

12

Mar

Balance mailboxes across databases – Exchange 2007

Posted by danovich  Published in Exchange, Powershell

There is a fantastic script on Kurtdepauw’s blog (http://kurtdepauw.wordpress.com/2007/11/10/dbbalancer-load-balance-your-exchange-mailbox-databases/) to assist in evenly balancing your Exchange 2007 databases so they are of similar size.

I have customized it slightly and highlight the 2 lines below as useful modifications:

Line 78 – added ‘| Where-Object {$_.Name -notlike “Archive Storage Group”}’ – this is very useful if you want to exclude certain databases from being touched by the balancing script

$DBs = Get-MailboxDatabase -Server $Global:hshParameters.MailboxServer | Where-Object {$_.Name -notlike "Archive Storage Group"}

Line 130 – added -PreserveMailboxSizeLimit switch – you will need to add this so that you can move mailboxes that exceed the database default limits

Move-Mailbox -Identity $Mailboxes[$intRandomMailbox] -TargetDatabase $Global:strSmallestDB.Split(";")[0] -PreserveMailboxSizeLimit -Confirm:$false

———-

Update 04/11/2009

I’ve been alerted that the link to Kurtdepauw’s blogis broken. I’ve posted the entire code below:

# DBBalancer Version 1.1
# Written by BoerLowie (sammybog@gmail.com)
# Modified by www.danovich.com.au - 12/03/2009 - www.danovich.com.au
#
# This script is used to maintain a balance between your different Exchange 2007 Mailbox Databases
#
# Configuration/Installation
# --------------------------
#
# To install the application, just place the script and the config file in C:\Program Files\DBBalancer
#
# The configuration is stored in DBBalancer.xml  Use the line below as a reference XML Config file (just paste it in notepad and save it as DBBalancer.xml
#
# <Objs Version="1.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj RefId="RefId-0"><TN RefId="RefId-0"><T>Deserialized.System.Collections.Hashtable</T><T>Deserialized.System.Object</T></TN><DCT><En><S N="Key">ThresholdInGB</S><I32 N="Value">5</I32></En><En><S N="Key">MailboxServer</S><S N="Value">S-BE-KI-EX</S></En></DCT></Obj></Objs>
#
# You can run the script in foreground or schedule it.  To schedule it, create a task using the following command line:
#
# PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1" -Command "C:\DBBalancer\DBBalancer.ps1"
#
# Make sure your account is at least an Exchange Server Administrator on the Mailbox Server.
#
# The following values are used in the xml file:
#  - ThresholdInGB:  The script will start to balance you databases if the difference between the biggest
#                    DB and the smallest DB exceeds this value.  This should be set to something like 5 GB.
#  - MailboxServer:  The MailboxServer to balance.  The script can be run from every machine with Exchange 2007 Management Tools
#                    installed on, so it needs to know which Mailbox Server it needs to connect to.  The script will balance all DB's on this
#                    mailbox server.
#
# Processing
# ----------
#
# The script will move a RANDOM mailbox from the Biggest DB to the Smallest DB until all DB are within the Threshold limit.  So if you
# set the Threshold to 5 GB, all DB's will be equally loaded with a maximum difference of 5 GB.
# Only one mailbox at a time will be moved to minimize user downtime.
#
# Logging
# -------
#
# You can follow the progress of the script in the Application Log.  Look for events of Source DBBalancer.
# Every mailbox move will be listed in the eventviewer.
#
# When all Mailbox Databases are balanced, the following will be displayed in the Event Viewer:
#  All Mailbox databases are balanced within the Threshold limit.

$ErrorActionPreference = "SilentlyContinue"

$Global:hshParameters = @{}
$Global:strBiggestDB = ""
$Global:strSmallestDB = ""
$Global:blnExecute = $True

Function Start-Init
{
$Global:hshParameters = Import-Clixml "C:\Exchange_Maintenance_Scripts\DBBalancer\DBBalancer.xml"
$Global:objEventLog = New-Object System.Diagnostics.EventLog("Application")
$Global:objEventLog.MachineName = "."
$Global:objEventLog.Source = "DBBalancer"
$Global:objEventLog.WriteEntry("Application Started." + [System.Environment]::NewLine + [System.Environment]::NewLine + `
"Target Mailbox Server :" + $Global:hshParameters.MailboxServer + [System.Environment]::NewLine + `
"Threshold in GB :" + $Global:hshParameters.ThresholdInGB)
}

Function Check-Prerequisites
{
If ((Get-MailboxDatabase -Server $Global:hshParameters.MailboxServer | Measure-Object).Count -gt 1)
{
Return $true
}
Else
{
Return $false
}
}

Function Get-BiggestandSmallestDB
{
Process
{
$DBs = Get-MailboxDatabase -Server $Global:hshParameters.MailboxServer | Where-Object {$_.Name -notlike "Archive Storage Group"}
$blnFirstRun = $true
foreach ($DB in $DBs)
{
$lonDBSize = (Get-MailboxStatistics -Database $DB.Identity | Measure-Object -Property TotalItemSize -Sum).Sum
If ($blnFirstRun -eq $true)
{
$Global:strBiggestDB = $DB.ServerName + "\" + $DB.Name + ";" + $lonDBSize
$Global:strSmallestDB = $DB.ServerName + "\" + $DB.Name + ";" + $lonDBSize
$blnFirstRun = $false
}
Else
{
If ($lonDBSize -lt $strSmallestDB.Split(";")[1])
{
$Global:strSmallestDB = $DB.ServerName + "\" + $DB.Name + ";" + $lonDBSize
}
If ($lonDBSize -gt $strBiggestDB.Split(";")[1])
{
$Global:strBiggestDB = $DB.ServerName + "\" + $DB.Name + ";" + $lonDBSize
}
}
}
}
}

Function Check-Threshold
{
If (([Long]$Global:strBiggestDB.Split(";")[1] - [Long]$Global:strSmallestDB.Split(";")[1]) -gt ($Global:hshParameters.ThresholdInGB * 1000000000))
{
Return $True
}
Else
{
Return $False
}
}

Function Do-MainLoop
{
While ($Global:blnExecute -eq $True)
{
Get-BiggestandSmallestDB
If (Check-Threshold -eq $True)
{
[Long]$lonDataToMove = ([Long]$Global:strBiggestDB.Split(";")[1] - [Long]$Global:strSmallestDB.Split(";")[1]) / 2
$Mailboxes = Get-Mailbox -Database $Global:strBiggestDB.Split(";")[0] -ResultSize "Unlimited"
$intRandomMailbox = New-Object System.Random
$intRandomMailbox = $intRandomMailbox.Next(0, ($Mailboxes.Count - 1))
$Global:objEventLog.WriteEntry("Moving " + $Mailboxes[$intRandomMailbox] + " from database " + $Global:strBiggestDB.Split(";")[0] + `
" to database " + $Global:strSmallestDB.Split(";")[0] + "." + [System.Environment]::NewLine + [System.Environment]::NewLine + `
"The mailbox has a size of " + ((Get-MailboxStatistics -Identity $Mailboxes[$intRandomMailbox]).TotalItemSize) + "ytes.")
Move-Mailbox -Identity $Mailboxes[$intRandomMailbox] -TargetDatabase $Global:strSmallestDB.Split(";")[0] -PreserveMailboxSizeLimit -Confirm:$false
}
Else
{
$Global:blnExecute = $False
}
}
Return $True
}

Start-Init
If (Check-Prerequisites -eq $true)
{
If (Do-MainLoop -eq $True)
{
$Global:objEventLog.WriteEntry("All Mailbox databases are balanced within the Threshold limit.")
}
}
Else
{
$Global:objEventLog.WriteEntry("Prerequisites check failed.  You probably have only 1 Mailbox Database and therefor we can't move mailboxes around.")
}

VN:F [1.9.3_1094]
please wait...
Rating: 0.0/10 (0 votes cast)
  • Share/Bookmark

Tags: automate, balance, database, dbbalancer, Exchange 2007, mailboxes, move mailbox, powershell, script

no comment

24

Feb

Email HTML report of largest Exchange 2007 mailboxes

Posted by danovich  Published in Exchange, Powershell

This PowerShell script queries the defined Exchange 2007 server and emails in HTML format the top 25 biggest mailboxes to the defined receipents. Simply create a scheduled task and you can have a automated weekly report:


# Name: top25.ps1
# Purpose: Report on the 25 largest mailboxes on an Exchange server and email this report in HTML format

# Set the Exchange server to run the query against

$ExchangeServer = “EXCHANGESERVERNAME”

# Run the query

$Top25Users = Get-MailboxStatistics -server $ExchangeServer |sort-object -Property totalitemsize -des |select-object Displayname, ItemCount, @{name=’Total Item Size (MB)’;expression={$_.totalitemsize/1MB}} -first 25 |Convertto-html

# Set the mail message properties

$FromAddress = “FROM@DOMAIN.COM.AU”
$ToAddress = “TO@DOMAIN.COM.AU”
$MessageSubject = “Weekly report: Top 25 biggest mailboxes on Exchange server ” + $ExchangeServer
$SMTPServer = “SMTPSERVER.DOMAIN.COM.AU”

# Create the mail message

$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $Top25Users
$SMTPMessage.IsBodyHtml = $true

# Send the message

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SMTPServer
$SMTPClient.Send($SMTPMessage)

VN:F [1.9.3_1094]
please wait...
Rating: 0.0/10 (0 votes cast)
  • Share/Bookmark

Tags: biggest mailboxes, Exchange 2007, powershell, top 25 users

no comment

12

Feb

Exchange 2007 Powershell script scheduled task?

Posted by danovich  Published in Exchange, Powershell

To run a Exchange 2007 Powershell script as a scheduled task you need to call the Exchange Shell as part of the command eg:

powershell -psconsolefile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command "& 'your script.ps1' "

VN:F [1.9.3_1094]
please wait...
Rating: 10.0/10 (1 vote cast)
  • Share/Bookmark

Tags: Exchange 2007, powershell, Scheduled Task

no comment

10

Feb

Set Exchange 2007 mailbox limits via group membership

Posted by danovich  Published in Exchange, Powershell

Powershell and Exchange 2007 allow for setting user mailbox limits (including warning and send / receive restrictions) based on Active Directory Group Membership.

For example, you can create a Powershell script that sets a 1GB mailbox limit for all users in the ‘Exchange Mailbox 1GB Storage Limit’ Active Directory Group.  Schedule this script to automatically run overnight and you no longer need to move users between mailstores or manually set limits in the account properties. Code below:

 


# Warning size = 975MB
# Stop sending email size = 990MB
# Stop sending and receiving email size = 1GB
# Variables below expressed as bytes 

$WarningSize = 1022361600
$StopSend = 1038090240
$StopAll = 1073741824
$Group = get-group "Exchange Mailbox 1GB Storage Limit"

forEach($Username in $Group.Members){Write-Host $Username; set-mailbox $Username -IssueWarningQuota $WarningSize -ProhibitSendQuota $StopSend -ProhibitSendReceiveQuota $StopAll -UseDatabaseQuotaDefaults $false}

VN:F [1.9.3_1094]
please wait...
Rating: 0.0/10 (0 votes cast)
  • Share/Bookmark

Tags: Exchange 2007, groups, mailbox limits

no comment

4

Feb

Exchange 2007 BuildToBuildUpgrade error

Posted by danovich  Published in Exchange

Whilst recently installing the Hub Transport role of Exchange 2007 SP1, the installation failed because it could not start the OpsMan server (it was disabled, another story). After enabling the service I went to reinstall the role and had the error shown below, indicated that I needed to perform the “BuildToBuildUpgrade” action.

After checking out the Exchange Team Blog (http://msexchangeteam.com/archive/2007/05/21/439529.aspx) it looked like I needed to remove a registry key.

Delete Watermark

Delete Watermark

Delete the Watermark key and restart your Exchange installation. For me, the Hub Transport role had successfully installed, it just looked like the installation said it had failed after unsuccessfully trying to start the OpsMgr services as one of the last tasks in the installation.

VN:F [1.9.3_1094]
please wait...
Rating: 10.0/10 (1 vote cast)
  • Share/Bookmark

Tags: BuildToBuildUpgrade, Exchange 2007, OpsMgr

1 comment

16

Dec

Exchange 2003 cluster with Symantec Endpoint Protection (SEP)

Posted by danovich  Published in AntiVirus, Exchange, Windows

After a reasonably painless recent rollout of SEP v11 to our fleet, we’ve come across some issues running it on a Windows 2003 Active-Passive Exchange 2003 cluster. Symptoms: nodes unresponsive, sometimes together, sometimes minutes after the other one – not even blue screened but completely unresponsive, nothing on the console.

Anyway the short of it was that we managed to get a memory dump and learned that system32\drivers\wpsdrvnt.sys had been causing the issues. Doesn’t ring a bell? Well it’s the Sygate Personal Firewall which has now been rolled into Symantec Endpoint Protection, the network threat protection component.

We obviously didn’t want to completely remove AV from our email system if possible, so we modified the installation to only contain the core files plus AV protection (see below)

2 weeks running like this and the problem has not reoccurred.

VN:F [1.9.3_1094]
please wait...
Rating: 0.0/10 (0 votes cast)
  • Share/Bookmark

Tags: cluster, Exchange, sep, symantec endpoint, windows 2003

no comment

Recent Posts

  • Installing SQL Server 2005 on a Windows Server 2008 R2 Cluster fails
  • Add the classic menu theme to Office 2007 & 2010
  • New Microsoft TS certifications
  • SCCM clients not installing in native mode

Categories

  • AntiVirus (1)
  • App-V (1)
  • Certificates (2)
  • Exchange (6)
  • Geek (14)
  • Office Communications Server (8)
  • Scripting (13)
    • Powershell (9)
  • SMS / SCCM (17)
  • Storage (3)
  • Tools (28)
  • VMWare (2)
  • Windows (31)

Archive

  • August 2010 (3)
  • July 2010 (1)
  • June 2010 (4)
  • May 2010 (4)
  • April 2010 (2)
  • March 2010 (9)
  • February 2010 (7)
  • January 2010 (8)
  • December 2009 (1)
  • November 2009 (4)
  • October 2009 (5)
  • September 2009 (3)
  • August 2009 (2)
  • June 2009 (3)
  • May 2009 (1)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (2)
  • December 2008 (7)

Random Quote

When I do good, I feel good; when I do bad, I feel bad. That’s my religion.. — Abraham Lincoln

Recommended Blogs

  • Michael Kleef blog
  • opsm.gr
  • Tao's System Management Blog

Tech Links

  • Dr Web online URL check
  • Live Mesh
  • Microsoft Connect
  • Microsoft Discussion Newsgroups
  • Microsoft IPD
  • Microsoft KB monitoring
  • Microsoft TechNet Forums
  • MX Lookup Tool
  • Speedtest
  • TVCatchup.com

Recent Entries

  • Installing SQL Server 2005 on a Windows Server 2008 R2 Cluster fails
  • Add the classic menu theme to Office 2007 & 2010
  • New Microsoft TS certifications
  • SCCM clients not installing in native mode
  • App-V sequenced applications not keeping settings / preferences
  • Group Policy Search
  • Great tool to install multiple applications at once
  • Windows 7 enable Recent Items via group policy
  • How to export RSS feeds in Outlook 2010
  • SuperFlow for SCCM Operating System Deployment via PXE

Recent Comments

  • goof1427 in Office Communicator error - Cannot synchronize add…
  • jrothlis in Add the classic menu theme to Office 2007 & 2010
  • liviui in Office Communicator error - Cannot synchronize add…
  • pcvchriskmg in Windows 7 enable Recent Items via group policy
  • danovich in Group Policy Search
  • jrothlis in Group Policy Search
  • bizzarro in Send SCCM task sequence email report
  • bizzarro in Send SCCM task sequence email report
  • ultrafris in Windows 7 enable Recent Items via group policy
  • danovich in Send SCCM task sequence email report
  • Random Selection of Posts

    • Script to automatically document SCCM configuration
    • App-V sequenced applications not keeping settings / preferences
    • OCS Remote Connectivity Testing Tool
    • HP iLO Integrated Remote Console is unavailable
    • Group Policy Search
    • Migrating email to Google Apps
    • INQ.EXE – See what storage a server can currently see
© 2009 - danovich.com.au - is proudly powered by WordPress.