How to copy / move emails from one mailbox to other using powershell

Prem Kumar Doddi 0 Reputation points
2025-01-29T05:37:24.1833333+00:00

I would like to copy emails from one mailbox to other using powershell

Microsoft Exchange Online
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,780 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 112.6K Reputation points MVP
    2025-01-29T07:14:26.3266667+00:00

    PowerShell on its own won't help you here. You have to leverage some EWS-based solution, such as this one: https://github.com/David-Barrett-MS/PowerShell-EWS-Scripts/wiki/Merge-MailboxFolders.ps1

    0 comments No comments

  2. Jake Zhang-MSFT 8,700 Reputation points Microsoft Vendor
    2025-01-29T08:12:54.0433333+00:00

    Hi @Prem Kumar Doddi ,

    Welcome to the Microsoft Q&A platform!

    Based on your description, to copy or move emails from one mailbox to another using PowerShell, you can use the Search-Mailbox cmdlet. Here are the steps to do this:

    1. Open PowerShell and run the following command to connect to Exchange Online:
    $UserCredential = Get-Credential
    Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName -Password $UserCredential.Password
    
    1. Make sure the user has the necessary permissions. The user must be a member of the Discovery Management group and be assigned the Mailbox Import Export role.
    2. Use the Search-Mailbox cmdlet to copy emails from the source mailbox to the target mailbox. Here are examples:
    $SourceUserName = "source@example.com"
    $TargetUserName = "target@example.com"
    $TargetFolderName = "TargetFolder"
    Search-Mailbox -Identity $SourceUserName -TargetMailbox $TargetUserName -TargetFolder $TargetFolderName -LogLevel Full
    
    1. If you want to move the email (i.e. copy it from the source and then delete it), you can use the -DeleteContent switch:
    Search-Mailbox -Identity $SourceUserName -TargetMailbox $TargetUserName -TargetFolder $TargetFolderName -LogLevel Full -DeleteContent
    
    1. Check the target mailbox to make sure the email was copied or moved successfully.

    Please feel free to contact me for any updates. And if this helps, don't forget to mark it as an answer.

    Best,

    Jake Zhang


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.