We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Export mailbox archive to PST

February 18, 2021 Views: 5476

The script can be used in business rules, custom commands and scheduled tasks to export the content of an Exchange mailbox archive to a Personal Storage Table (PST) file. To add it to your rule, command or task, use the Run a program or PowerShell script action.

Note: To be able to export mailbox archive, the Adaxes service account must be assigned to the Mailbox Import Export role in Exchange. To use a different account, specify the credentials of the necessary account it in the Run as section of your Run a program or PowerShell script action.

Parameters:

  • $exchangeServer - Specifies the Fully Qualified Domain Name (FQDN) of the Exchange Server that will be used to perform the export.
  • $filePath - Specifies the path to the PST file with the archive contents.
You can use value references in the PST file path. When the script will be executed, the value references will be replaced with property values of the user on which it is executed. For example, if you specify \\server\share\Archive\%username%.pst, and the script is executed on a user whose username is jdoe, the path will be \\server\share\Archive\jdoe.pst.
Edit Remove
PowerShell
$exchangeServer =  "exchangeserver.domain.com" # TODO: modify me
$filePath = "\\server\share\Archive\%username%.pst" # TODO: modify me

try
{
    # Connect to the Exchange Server
    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI "http://$exchangeServer/PowerShell"
    Import-PSSession $session -DisableNameChecking -AllowClobber -CommandName "Get-MailboxExportRequest", "Remove-MailboxExportRequest", "New-MailboxExportRequest"

    # Clear all previous export requests with the same name
    Get-MailboxExportRequest -Name "%username%" | Remove-MailboxExportRequest -Confirm:$False
    try
    {
        # Initiate export of the mailbox archive
        New-MailboxExportRequest "%username%" -FilePath $filePath -Name "%username%" -IsArchive -ErrorAction Stop
    }
    catch
    {
        $Context.LogMessage("Failed to initiate export of mailbox archive for %username%. Error message: " + $_.Exception.Message, "Warning")
    }
}
finally
{
    # Close connection to the Exchange Server
    if ($session) { Remove-PSSession $session }
}

Comments 2
avatar
KVM Mar 20, 2019
We get this error when running the script above, what should we use to sequentially get ever users mailbox archive to export?

Failed to initiate export of mailbox archive for %username%. Error message: The operation couldn't be performed
because '%username%' couldn't be found.
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
+ PSComputerName : localhost
avatar
Support Mar 20, 2019

Hello,

 

Could you, please, specify how exactly you are executing the script? A screenshot of the Custom Command, Scheduled Task or Business Rule executing the script would be much appreciated. You can send it to our support email support[at]adaxes.com.


Also, could you provide us with the exact script you are using with all the modifications in TXT format?

Leave a comment
Loading...

Got questions?

Support Questions & Answers