Before we can use this script, please follow this steps at the office 365 admin portal.

You have to do this one time.

• Login to Office 365 portal and go to ‘Exchange Admin Center’. 
• Select the ‘Permissions’ tab and under ‘Admin Roles’, add the Office 365 Administrator as a member of Discovery Management, Recipient Management, Compliance Management and Organization Management. 
• Under Discovery Management, make sure to add the roles for Mailbox Search and Mailbox Import Export

 

 

PowerShell
Edit|Remove
$sessionPS = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/?proxymethod=rps -Credential $userCredentialEO -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue 
 
Import-pssession $sessionPS -DisableNameChecking -AllowClobber 
 
$targetmailbox = "target@domain.com" 
 
$targetfolder = "Target Folder" 
 
$usertomove = "email@domain.com" 
 
Search-Mailbox –Identity $usertomove –TargetMailbox $targetmailbox –TargetFolder $targetfolder 
 
Remove-pssession $sessionPS