February 24 2009

Email HTML report of largest Exchange 2007 mailboxes

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)



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------

February 10 2009

Set Exchange 2007 mailbox limits via group membership

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}

February 4 2009

Exchange 2007 BuildToBuildUpgrade error

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.