Link to home
Start Free TrialLog in
Avatar of Michael Hager
Michael HagerFlag for United States of America

asked on

Move one users email to another in Exchange 365

Hi all,


I'm trying to move one user's complete mailbox to a folder in another user account.  I am using Exchange 365.  I'm attempting to do this using Power Shell.


I run the following script:


Search-Mailbox (usertomove@domain.com) -TargetMailbox (mailto:Usergettingemail@domain.com) -TargetFolderName Primary Mailbox\Inbox\folder created


The parenthesis are just here for clarification, they are not in the command.  I get the following error:


A positional parameter cannot be found that accepts argument 'Mailbox\Inbox\Jason'.

    + CategoryInfo          : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException

    + FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox

    + PSComputerName        : outlook.office365.com


The parenthesis are not in the command just here to clarify, I have also checked that the folder has been created off the inbox of the user receiving the email, and the account name is correct.


What am I missing in the command I'm trying to run.  I have found a few articles and none of the scripts work.


Thanks everyone in advance.




Avatar of Amit
Amit
Flag of India image

Try this:
Search-Mailbox -Identity "usertomove@domain.com" -TargetMailbox "Usergettingemail@domain.com" -TargetFolderName "Inbox/folder created"
Avatar of Michael Hager

ASKER

Thanks Amit for the reply.  After running the script that way I get a prompt that is

>>

It looks like it wants more input.
Try this:
$Mailbox = "usertomove@domain.com"
$TargetMailbox = "Usergettingemail@domain.com"
$TargetFolderName = "folder created"

Search-Mailbox -Identity $Mailbox -TargetMailbox $TargetMailbox -TargetFolderName "$($TargetMailbox):\Inbox\$TargetFolderName" -LogLevel Full -ErrorAction Stop
I apoligize in advance of not being great and running scripts:

I first set up the variables:

$Mailbox = "usertomove@domain.com"
$TargetMailbox = "Usergettingemail@domain.com"
$TargetFolderName = "folder created"

It took the variables

I then ran:

Search-Mailbox -Identity $Mailbox -TargetMailbox $TargetMailbox -TargetFolderName "$($TargetMailbox):\Inbox\$TargetFolderName" -LogLevel Full -ErrorAction Stop

It produced:

A parameter cannot be found that matches parameter name 'TargetFolderName'.
At C:\Users\myuser.domain\AppData\Local\Temp\tmp_5xaqykvv.sxg\tmp_5xaqykvv.sxg.psm1:62016 char:9
+         $steppablePipeline.End()
+         ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Search-Mailbox
    + PSComputerName        : outlook.office365.com

Am I supposed to change something in the last command.  I figured that since it had the variables I didn't need to change anything.

Thanks for all the help.
My apologies, I didn't notice you are using Exchange Online. For that new command is:

New-MailboxSearch -Name "MailboxToMove" -SourceMailbox "usertomove@domain.com" -TargetMailbox "usergettingemail@domain.com" -TargetFolder "Inbox/folder created" -LogLevel Full -IncludeUnsearchableItems -SearchDumpster
 
Refer: https://learn.microsoft.com/en-us/powershell/module/exchange/new-mailboxsearch?view=exchange-ps

I assume you have right permissions to search and export the mailbox
Thanks for the info.  I do have permissions to do anything as I'm the Global Administrator.  I ran:

New-MailboxSearch -Name "MailboxToMove" -SourceMailbox "usertomove@domain.com" -TargetMailbox "usergettingemail@domain.com" -TargetFolder "Inbox/folder created" -LogLevel Full -IncludeUnsearchableItems -SearchDumpster

For -Name, I tried the users name, and the users email address.  Both produced:

A parameter cannot be found that matches parameter name 'TargetFolder'.
    + CategoryInfo          : InvalidArgument: (:) [New-MailboxSearch], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,New-MailboxSearch
    + PSComputerName        : outlook.office365.com

I'm wondering if I need to upgrade my Powershell.  I'm going to do that now.
Hello Michael,
1.  If you haven't already done this, soft delete the user whose mailbox you need to move.  Then wait about 15 minutes
2. In powershell for Exchange Online run the below command:
Get-recipient "Displaynameofthesoftdeleteduser" -IncludeSoftDeletedRecipients | Select Identity,DisplayName,ExchangeGuid,ArchiveGuid,primarysmtpaddress,when*

If the user has been successfully soft deleted the words soft deleted will show up in the identity.  If not wait a little longer.

Use that same command to get the guids of the target mailbox.

3. Once the source user is soft deleted you may now restore the mailbox data to the target mailbox using the ExchangeGuid from the source mailbox from the command in line 2

*On the target mailbox run the below command to get the exact path of the folder you are restoring to
Get-MailboxFolderStatistics "emailaddressoftargetmailbox" | Select Name,FolderPath | Sort Name | export-csv C:\temp\folderpaths.csv -nti

New-MailboxRestoreRequest -Name "MailboxRestore" -SourceMailbox "exchangeguidnumberfromsourcemailbox" -TargetMailbox "exchangeguidfromthetargetmailbox -TargetRootFolder  "putfolderpathoftargetmailbox" -AllowLegacyDNMismatch -AcceptLargeDataLoss -BadItemLimit Unlimited -LargeItemLimit Unlimited -ConflictResolutionOption KeepSourceItem -verbose

 
Got it all...thanks everyone for the help.....
Late to the party but you could also just convert the existing user mailbox into a shared mailbox, give full access, then let the other user access it that way (and optionally pull the folder(s) over). Just a thought for next time :-)
I do have another user to do this with and I like this idea.  I have to pull the license from the old user, so not sure if after it is shared that Exchange 365 will kill the folders.  I'll have the new user move everything first...lol

Thanks for the input.
ASKER CERTIFIED SOLUTION
Avatar of Greg Besso
Greg Besso
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial