Skip to content

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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the user
$user = $admService.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