Powershell – how to backup/export office 365 email to pst in exchange hybrid environment

exchange-2013exchange-hybridexportmicrosoft-office-365powershell

We have a exchange hybrid environment. (some users are in onpremises exchange and some users are office 365. )

When we want to export emails from onpremis we use , below command to export mail box and archive.

 New-MailboxExportRequest -Mailbox "user" -FilePath \\mysrv\l$\PST\Mailbox-user.pst; New-MailboxExportRequest -Mailbox "user" -IsArchive  -FilePath \\mysrv\l$\PST\Mailbox-user-archive.pst -confirm:$false

New-MailboxExportRequest works fine for onpremis users not for office 365.
is there a way to export office 365 user mail box to pst using powershell ?

What i have tried so far:

I logged to office 365

$UserCredential = Get-Credential
Import-Module MSOnline

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

Import-PSSession $Session

and tried New-MailboxExportRequest

But it generates an error. apparently office 365 dont know that command

PS C:\Users\pp> New-MailboxExportRequest
New-MailboxExportRequest : The term 'New-MailboxExportRequest' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ New-MailboxExportRequest
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-MailboxExportRequest:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Also Get-Command *Export* results are as follows

enter image description here

Tried googling, yet could not find a viable option. can some one guide me please ? What is the compatible command in office environment to do this ?

PS:
I have tried https://www.codetwo.com/admins-blog/how-to-export-office-365-mailboxes-to-pst-using-ediscovery/ with E5 license and it works in the GUI perfectly. but my concern is even with e-discovery, and having license any possibility to do it with powershell ? i mean to script/automate via powershell ?

Best Answer

You can't export Exchange Online mailbox directly to PST via PowerShell with built-in tools. Required New-MailboxExportRequest doesn't exist Online (or is not exposed to us mortals).

You can:

  • eDiscovery, that seems to be GUI-only.
  • Offload/migrate mailbox to on-prem Exchange and run New-MailboxExportRequest on-prem (and migrate back to Exchange Online if needed)
  • Use various 3rd party tools, that perform export via EWS or MAPI
  • Script delegation full access, Outlook bind to delegated mailbox and export to PST. Technically very likely possible but I've never seen anyone do it. I haven't looked deeply into eDiscovery but I believe that's more-less how eDiscovery does export to PST (Old Exchanges also used to bind to Outlook for PST export). But without significant MAPI experience, Outlook COM model is quite complex to use (I've done some Outlook scripting but emulating PST export is challenging to say the least).

I'm as frustrated as you are. Exporting mailboxes for departing users for long-term storage is needlessly annoying. If we could just export to Azure Blob just as with import, it'd be a good start.