How to copy emails from one mailbox to another in Office 365 using Powershell

Copy emails from one mailbox to another can be a tedious task, especially when you have a large number of emails to transfer. Luckily, with the use of PowerShell, you can automate the process and make it more efficient. In this blog post, we will guide you through the steps to copy emails from one mailbox to another in Office 365 using PowerShell.

Step 1: Connect to Exchange Online

The first step is to connect to Exchange Online using PowerShell. Open PowerShell on your computer and run the following command:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

This will prompt you to enter your Office 365 credentials. Once you enter them, PowerShell will connect to Exchange Online.

Step 2: Create a CSV file

Next, create a CSV file containing the email addresses of the source and destination mailboxes. The CSV file should have two columns: “SourceMailbox” and “TargetMailbox”. For example:

SourceMailbox,TargetMailbox
user1@contoso.com,user2@contoso.com

Save this file on your computer.

Step 3: Copy emails from one mailbox to another

Now, we can use PowerShell to copy emails from the source mailbox to the destination mailbox. Run the following command:

$CSVFile = "C:\Path\To\CSV\File.csv"
$Mailboxes = Import-Csv $CSVFile
ForEach ($Mailbox in $Mailboxes) {
    New-MailboxImportRequest -Mailbox $Mailbox.SourceMailbox -FilePath "\\Server\Share\Path\To\PST\file.pst" -TargetRootFolder "Inbox" -Name "Import" -ContentFilter {(Received -lt '01/01/2023')} -BadItemLimit 10
    Get-MailboxImportRequest | where {$_.Status -eq "Completed"} | Remove-MailboxImportRequest
    New-MailboxExportRequest -Mailbox $Mailbox.TargetMailbox -FilePath "\\Server\Share\Path\To\PST\file.pst" -ContentFilter {(Received -lt '01/01/2023')} -BadItemLimit 10
    Get-MailboxExportRequest | where {$_.Status -eq "Completed"} | Remove-MailboxExportRequest
}

This command will import emails from the source mailbox to a PST file and then export them to the destination mailbox. You can modify the parameters as needed, such as the date range of the emails to copy and the folder to copy them to.

Step 4: Verify the copy

After the command completes, you can verify that the emails were copied successfully by logging into the destination mailbox and checking that the emails are present.

In conclusion, copying emails from one mailbox to another in Office 365 can be done quickly and efficiently using PowerShell. By following the steps outlined in this blog post, you can automate the process and save time and effort.