Exporting mailboxes
To export the content of an Exchange mailbox to a Personal Storage Archive (PST) file, use the IAdmExportExchangeMailboxOps interface supported by all user objects. The following code sample exports a user's mailbox to a PST file.
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$filePath = "\\SERVER\Backups\JSmith.pst"
# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Bind to the user
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Export mailbox
$requestId = $user.CreateMailboxExportRequest($filePath, 0, 0)
# Get mailbox export request info
$requestInfo = $user.GetMailboxExportRequestInfo($requestId, $false)
while($requestInfo.Status -eq "ADM_EXPORTMAILBOXSTATUS_INPROCESS")
{
Start-Sleep -Seconds 30
$requestInfo = $user.GetMailboxExportRequestInfo($requestId, $false)
}
# Status
Write-Host "Status: " -NoNewline
switch ($requestInfo.Status)
{
"ADM_EXPORTMAILBOXSTATUS_SUCCEEDED"
{
Write-Host "The mailbox was exported successfully."
}
"ADM_EXPORTMAILBOXSTATUS_FAILED"
{
Write-Host $requestInfo.FailureMessage
}
}
See also
- Performing Exchange tasks
- IAdmExportExchangeMailboxOps
- Writing ADSI scripts
- Server-side scripting
- Online script repository