1. Skip to Menu
  2. Skip to Content
  3. Skip to Footer

Экспорт почтовых ящиков Exchange

 

Нашел в сети очень нужный PowerShell скрипт для массового экспорта почтовых ящиков. 100% подходит для Exchange 2010. Позволяет делать выгрузку в pst-файлы. В зависимости от параметра ($Server или $Database) выгружает почтовые ящики всего сервера или же отдельной почтовой базы.

Сохраните указанный ниже код в файл MassExport.ps1 и запустите командой:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'c:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; .\MassExport.ps1"

---------------------------------------------------------- Начало скрипта -----------------------------------------------------------

###############

# Settings   #

###############

# Pick ONE of the two below. If you choose both, it will use $Server.

$Server = "EXCHANGE_SERVER_NAME"

$Database = ""

# Share to export mailboxes to. Needs R/W by Exchange Trusted Subsystem

# Must be a UNC path as this is run by the CAS MRS service.

$newname = "Exchange2_$(Get-Date -f dd.MM.yyyy)"

mkdir \\SERVER_NAME\EXPORT_FOLDER

$ExportShare = "\\SERVER_NAME\EXPORT_FOLDER\$newname"

# After each run a report of the exports can be dropped into the directory specified below. (The user that runs this script needs access to this share)

# Must be a UNC path or the full path of a local directory.

$ReportShare = "\\SERVER_NAME\EXPORT_FOLDER\Reports"

# Shall we remove the PST file, if it exists beforehand? (The user that runs this script needs access to the $ExportShare share)

# Valid values: $true or $false

$RemovePSTBeforeExport = $false

Set-AdServerSettings -ViewEntireForest $true

###############

# Code       #

###############

if ($Server)

{

   if (!(Get-ExchangeServer $Server -ErrorAction SilentlyContinue))

   {

       throw "Exchange Server $Server not found";

   }

   if (!(Get-MailboxDatabase -Server $Server -ErrorAction SilentlyContinue))

   {

       throw "Exchange Server $Server does not have mailbox databases";

   }

   $Mailboxes = Get-Mailbox -Server $Server -ResultSize Unlimited

} elseif ($Database) {

   if (!(Get-MailboxDatabase $Database -ErrorAction SilentlyContinue))

   {

       throw "Mailbox database $Database not found"

   }

   $Mailboxes = Get-Mailbox -Database $Database

}

if (!$Mailboxes)

{

   throw "No mailboxes found on $Server"

}

if (!$Mailboxes.Count)

{

   throw "This script does not support a single mailbox export."

}

# Pre-checks done

# Make batch name

$date=Get-Date

$BatchName = "Export_$($date.Year)-$($date.Month)-$($date.Day)_$($date.Hour)-$($date.Minute)-$($date.Second)"

Write-Output "Queuing $($Mailboxes.Count) mailboxes as batch '$($BatchName)'"

# Queue all mailbox export requests

foreach ($Mailbox in $Mailboxes)

{

   if ($RemovePSTBeforeExport -eq $true -and (Get-Item "$($ExportShare)\$($Mailbox.Alias).PST" -ErrorAction SilentlyContinue))

   {

       Remove-Item "$($ExportShare)\$($Mailbox.Alias).PST" -Confirm:$false

   }

   New-MailboxExportRequest -BatchName $BatchName -Mailbox $Mailbox.Alias -FilePath "$($ExportShare)\$($Mailbox.Alias).PST"

}

Write-Output "Waiting for batch to complete"

# Wait for mailbox export requests to complete

while ((Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"}))

{

   sleep 60

}

# Write reports if required

if ($ReportShare)

{

   Write-Output "Writing reports to $($ReportShare)"

   $Completed = Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -eq "Completed"} | Get-MailboxExportRequestStatistics | Format-List

   if ($Completed)

   {

       $Completed | Out-File -FilePath "$($ReportShare)\$($BatchName)_Completed.txt"

   }

   $Incomplete = Get-MailboxExportRequest -BatchName $BatchName | Where {$_.Status -ne "Completed"} | Get-MailboxExportRequestStatistics | Format-List

   if ($Incomplete)

   {

       $Incomplete | Out-File -FilePath "$($ReportShare)\$($BatchName)_Incomplete_Report.txt"

   }

}

# Remove Requests

Write-Output "Removing requests created as part of batch '$($BatchName)'"

Get-MailboxExportRequest -BatchName $BatchName | Remove-MailboxExportRequest -Confirm:$false

---------------------------------------------------------- Конец скрипта -----------------------------------------------------------

Комментарии   

 
0 #1 gaomega 27.03.2015 17:48
поставил коммент на
$Server = "EXCHANGE_SERVER_NAME"
и на
$newname = "Exchange2_$(Ge t-Date -f dd.MM.yyyy)"

после этого скрипт начал очень удачно выгружать в pst нужные мне базы данных
Цитировать
 

Добавить комментарий