The scripts export an on-premises Exchange mailbox to a PST file. The first script initiates the mailbox export, and the second one checks whether mailbox export is complete as well as reports error messages that occurred in the export process (if any).
1. Initiate Mailbox Export
This script initiates mailbox export and saves the export request ID to a certain property of the corresponding user account so it would be possible to track the export request in the future.
Parameters:
- $filePath - Specifies a template for a path to the PST file that will be created by the script. You can use value references (e.g. %username%) in the path. When the script is executed, they will be replaced with corresponding property values of the user account.
- $requestIdProperty - Specifies the property of the user account in which export request ID will be saved. For this purpose, we recommend using one of Adaxes custom properties that can store string values (e.g. CustomAttributeText1). They are not stored in AD, but can be used the same as any other properties of AD objects.
$filePath = "\\Server\Share\%username%.pst" # TODO: modify me
$requestIdProperty = "adm-CustomAttributeText1" # TODO: modify me
# Create mailbox export request
$requestId = $Context.TargetObject.CreateMailboxExportRequest($filePath, 0, 0)
# Save request id
$Context.TargetObject.Put($requestIdProperty, $requestId)
$Context.TargetObject.SetInfo()
2. Track Mailbox Export Process
This script checks whether mailbox export is complete and sends an email message with errors that occurred in the export process (if any). We recommend creating a scheduled task using the script. It will check mailboxes whose export was started on a periodical basis.
Parameters:
- $requestIdProperty - Specifies the property of the user account where request ID is saved. It must be the same property as specified in script 1.
- $to - Specifies the email address of the recipient of emails with failure messages.
- $subject - Specifies the subject of emails with failure messages.
- $message - Specifies the text of emails with failure messages. In the text, the {0} placeholder will be replaced with the mailbox name, and the {1} placeholder will be replaced with the export request failure message.
$requestIdProperty = "adm-CustomAttributeText1" # TODO: modify me
# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Mailbox export failed" # TODO: modify me
$message = "
Mailbox: {0}
Failure Message: {1}" # TODO: modify me
# Get mailbox export request info
$requestId = $Context.TargetObject.Get($requestIdProperty)
$requestInfo = $Context.TargetObject.GetMailboxExportRequestInfo($requestId, $False)
switch ($requestInfo.Status)
{
"ADM_EXPORTMAILBOXSTATUS_INPROCESS"
{
return
}
"ADM_EXPORTMAILBOXSTATUS_FAILED"
{
# Send mail
$message = [System.String]::Format($message, @($Context.GetDisplayNameFromAdsPath($Context.TargetObject.AdsPath), $requestInfo.FailureMessage))
$Context.SendMail($to, $subject, $message, $NULL)
# Remove export request ID
$Context.TargetObject.Put($requestIdProperty, $NULL)
$Context.TargetObject.SetInfo()
}
"ADM_EXPORTMAILBOXSTATUS_SUCCEEDED"
{
# Remove export request ID
$Context.TargetObject.Put($requestIdProperty, $NULL)
$Context.TargetObject.SetInfo()
}
}