With continue operation of exchange in large enterprise, user mailbox and exchange database will keep growing.
Exchange has provide significant mechanism to deal with, include archive(by online/by outlook), online database maintenance, mailbox database defragment and compact.
However, the mailbox database still will keep growing. It is also some kind of danger to operate mailbox mdb file directly using eseutil, and require long offline time.
On the other hand, there are many limitation that keep storage from un-limited growing. For example, Hyper-V virtual disk (VHD) has 2T maximum size.
To prevent the continue storage growth requirement and keep server in best performance, we keep all enterprise mailbox users to export and purge their mailbox and start with clean mailbox in a fixed period, saying ,every year, by following script.
ExportUser.PS1
$users = Import-Csv c:\export\UserToExport.CSV
$Root = “\\publicstorage.mydomain.com\fileshare\MailboxArchive\”
$Date = Get-Date -format yyMMdd
$BatchName = “Export”+$Date
foreach ($item in $users)
{
$User = $item
$ArchiveFilePath = $Root+$User+”\Archive”+$Date+”.pst”
$MailboxFilePath = $Root+$User+”\Mailbox”+$Date+”.pst”
New-Item -Path $Root -name “$User” -ItemType “directory” -force
New-MailboxExportRequest -MailBox $User -FilePath “$ArchiveFilePath” -BatchName $BatchName -DomainController dcserver.mydomain.com -ExcludeDumpster:$true -IsArchive:$true
New-MailboxExportRequest -MailBox $User -FilePath “$MailboxFilePath” -BatchName $BatchName -DomainController dcserver.mydomain.com -ExcludeDumpster:$true -IsArchive:$false
}
After export ,we will create a new mailbox database,set all mailbox to the new db and notify user.
$newdb=’corp2014′
$mailboxExports = Get-MailboxExportRequest |Where {$_.Status -eq “Completed”} | Get-MailboxExportRequestStatistics
# Define and create the message
$strTo = “”
$strFrom = “notification@mydomain.com”
$strSubject = “Mailbox Purge Notification”
$strBodyFront = “Your mailbox has been archived and purged. All of previous mail is stored under”
$strBodyEnd=”,you can find them back by add then under file–> account settings –> data file on outlook.”
$strCc=”it@mydomain.com”
# Define the SMTP server
$strSMTPServer = “smtp.mydomain.com”
$objSMTP = New-Object System.Net.Mail.SMTPClient –ArgumentList $strSMTPServer
$objSMTP.Credentials =New-Object System.Net.NetworkCredential(……..)
ForEach ($export in $mailboxExports)
{
$file = $export.FilePath
$user = $export.SourceAlias
$acl = Get-Acl “$file”
$userAccount = new-object System.Security.Principal.NTAccount(“mydomain.com”, $user)
$acl.SetOwner($userAccount)
#$accessRule = $acl.GetAccessRules($true,$true,[System.Security.Principal.NTAccount])
$newAccessRule = New-Object -Type System.Security.AccessControl.FileSystemAccessRule -ArgumentList $userAccount,FullControl,Allow
#$accessRule.Add($newAccessRule)
$acl.AddAccessRule($newAccessRule)
Set-Acl “$file” $acl
Write-Host $file
Disable-Mailbox $user -Confirm:$false
Enable-Mailbox $user -Database $newdb -Confirm:$false
# Define and create the message
$strBody = $strBodyFront + $file + $strBodyEnd
$strTo = ($user+”@mydomain.com”)
$objMessage = New-Object System.Net.Mail.MailMessage –ArgumentList $strFrom,$strTo , $strSubject, $strBody
$objMessage.CC.Add(“it@mydomain.com”)
# Send the message
$objSMTP.Send($objMessage)
}
Remove-MailboxExportRequest $export.Identity -Confirm:$false
}