Powershell Script to Export Exchange mailbox to smaller PST Chunks

Powershell Script to Export Exchange mailboxes in 20GB PST allotments for upload to Mimecast

 

Import-Module activedirectory

$TargetUserName="jsmith"
$Useremail="jsmith@domain.com
$Location = "\\10.1.10.18\ArchiveExport\"

$FirstEmail = Get-MailboxFolderStatistics $TargetUserName -IncludeOldestAndNewestItems | ? {$_.OldestItemReceivedDate} | Sort-Object OldestItemReceivedDate | Select -ExpandProperty OldestItemReceivedDate -First 1
$FirstEmail = $FirstEmail.ToString("MM/dd/yyyy")

$finish = $FirstEmail

#The end date of when the last email wants to be exported , if using Mimecast this will be the date of enabling archiving
$startdate = Get-Date

$startofmonth = Get-Date $startdate -day 1 -hour 0 -minute 0 -second 0

$endofmonth = (($startofmonth).AddMonths(1).AddSeconds(-1))

$pstnumber = 1

do {
$startvalue = Get-Date -format d -Date $startofmonth

$endvalue = Get-Date -format d -Date $endofmonth

New-MailboxExportRequest $TargetUserName -ContentFilter "((Received -gt '$startofmonth') -and (Received -lt '$endofmonth'))" -FilePath $Location$Useremail".pst" -Confirm:$false

$ExportStats = Get-MailboxExportRequest -Mailbox $TargetUserName
$ExportStatus = $ExportStats.Status

Do{
Start-Sleep 10
$ExportStats = Get-MailboxExportRequest -Mailbox $TargetUserName
$ExportStatus = $ExportStats.Status
} while ($ExportStatus -eq "Queued" -or $ExportStatus -eq "InProgress")

Start-Sleep 30

Get-MailboxExportRequest -mailbox $targetusername -Status "Completed" | Remove-MailboxExportRequest -Confirm:$false

Start-Sleep 30

if((Get-Item $Location$useremail".pst").length -gt 20gb) {
Rename-Item $Location$Useremail”.PST” $Location$Useremail”.“$pstnumber”.PST”
$pstnumber++
}

$startofmonth = (($startofmonth).AddMonths(-1))

$endofmonth = (($startofmonth).AddMonths(1).AddSeconds(-1))

Start-Sleep 30

}

while ($startofmonth -ge $finish)
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Trackback from your site.