How to Export all Email from Exchange Server 2010 for a Specified Time Period

skbryan
skbryan used Ask the Experts™
on
Hi.  I need to export all email for all users from our 2010 Exchange Server (about 200) for a two month period (11/21/2016 to 02/01/2017) to be ingested by Intermedia for onpremise archiving.   I'm not a power shell guru and I need help.  I've looked at several scripts, but was left more confused than not.  

 Would it be something like this?  

 Get-Mailbox -Database DB1 | Export-Mailbox  -StartDate "11/21/2016" -EndDate "02/01/2017" - \\10.10.10.10\EmailBackup \.pst

 And would that include all their email even if they've moved it into folders that they created within their mailbox?

 Please assist.  Thank you very much!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Patrick BogersDatacenter platform engineer Lindows
Commented:
Hi,

I think more like

$Export=.\mailboxes.txt
 foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '21/11/2016') -and (Received -gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.10.10\EmailBackup\$($i).pst" }

This Will export all mailboxes to their OWN pst file. (Incl all subfolders)

Cheers

Author

Commented:
Thank you very much for your reply.  I ran the script and this is what I got:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS N:\> $Export=.\mailboxes.txt
The term '.\mailboxes.txt' is not recognized as the name of a cmdlet, function, scri
 the spelling of the name, or if a path was included, verify that the path is correc
At line:1 char:24
+ $Export=.\mailboxes.txt <<<<
    + CategoryInfo          : ObjectNotFound: (.\mailboxes.txt:String) [], CommandNo
    + FullyQualifiedErrorId : CommandNotFoundException

PS N:\>   foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Recei
 -gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }

Also, will this pick up all sent messages as well, correct?  Thank you very much for your help!!!!!
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hi

In the local dir i expect a file called mailboxes.txt in which i expect to have all mailboxes to be exported.

Yes this included sent items, deleted items, custom dirs everything.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I know we are close!  

PS N:\> $Export=.\mailboxes.txt foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '21/11
/2016') -and (Received -gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }
Unexpected token 'in' in expression or statement.
At line:1 char:39
+ $Export=.\mailboxes.txt foreach ($i in <<<<  ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '21/1
1/2016') -and (Received -gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

PS N:\>

in notepad, do I list them on each line, like:
rsmith
lsmith
rjones
etc.

Thank you very much!
Patrick BogersDatacenter platform engineer Lindows

Commented:
In notepad Yes thats the way, we work with the displayname.
You are trying two PS commands in one line, this is not working.

Either you put the two lines in a file and call it xxxx.ps1 and run this from PS.
Or you open PS ISE and run multiple lines from there at Once.

Author

Commented:
Here is what I got:

PS N:\> $Export=.\mailboxes.txt
PS N:\> foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '21/11/2016') -and (Received -
gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }
New-MailboxExportRequest : Cannot validate argument on parameter 'Mailbox'. The argument is null. Supply a non-null arg
ument and try the command again.
At line:1 char:139
+ foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '21/11/2016') -and (Received -gt '0
2/01/2017')} -Mailbox <<<<  $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }
    + CategoryInfo          : InvalidData: (:) [New-MailboxExportRequest], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Exchange.Management.RecipientTasks.NewMailbox
   ExportRequest

Ran the first command just fine.  On the second one, not so much.  Thank you.

Author

Commented:
we are running exchange 2010 SP3 Rollup 7, Version: 14.03.0210.002

Thank you.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Which version PS?
$PSVersionTable

Author

Commented:
PS N:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
Commented:
If I replace the command ($Export) with (Get-Mailbox), it appears to want to try and work - I now see a queued list.

foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -ContentFilter {(Received -lt '11/21/2016') -and (Received -gt '02/01/2017')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }

I wonder what I will get or if it will work. . .
Patrick BogersDatacenter platform engineer Lindows

Commented:
Nice find.
I strongly recommend upgrading powershell to 3 or 4.

Awaiting outcome

Author

Commented:
It appears to be backing up the email boxes s l o w l y, probably because I am in a hurry.  Don't want to open one yet because I don't want to mess anything up.  

If I upgrade Powershell, will it still be compatible with my version of Exchange?  (I understand that some of the commands may be different).  I am a total PS newbie . . . pretty sure that you already knew that.

Thank you very much for all your help, and I will let you know how this comes out.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Ahh off course...Exchange 2010 cmdlets and scripts require PS 2.0 *sigh*

I understand it is slowly, this was intended so we do not interupt user experience.
This script Will do one pst at a time so it is ok to copy/open one that has finished.

Hear from you later. Glad we Got it working as desired.

Author

Commented:
Wah!  It appears to be stalled.  It stopped working about the same time that I disconnected from the server, about 3:34pm.  (Obviously, I removed our company and username from the attached screenshots).  

Screenshot1
Screenshot of folder where the export is being dumped (not showing usernames).

Screenshot2
Is there a way to "goose" the command?  Thank you.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hi

Too bad but logical since the process in running under your security context.

What do you mean by Goose the command? Have it run while you are offline?
Guess we can let it run as scheduled task which runs one time on demand under the local system security context.

No username shown can be caused by the leading dollarsign in $($i).pst
If you do a dir in elevated dir, does it show usernames?

Author

Commented:
I'm logged into the server and my command is still up (I never logged out, just disconnected), but it isn't going anywhere.  How would I get it to run whether or not I am connected to the server or not?  I am a domain admin with Mailbox Import Export rights.

By "goose", I meant a command like, "Hey, you still need to run the above command. Please resume where you left off.".   If I reenter and start over, won't it still stall if I am not connected?

The usernames and all that other stuff is there, I just removed it for privacy's sake.  

Thank you for your help.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Ok Nice.
What does below commands say?
Get-MailboxExportRequest | where {$_.status -eq "Completed"} | Remove-MailboxExportRequest
Get-MailboxExportRequest | where {$_.status -eq "Failed"} | Remove-MailboxExportRequest

Next i wonder what rollup and cu you are running. I know the stuck issue is pre-ru6

Author

Commented:
Running Exchange 2010 SP3 Rollup 7, Version: 14.03.0210.002

Get-MailboxExportRequest | where {$_.status -eq "Completed"} | Remove-MailboxExportRequest
Get-MailboxExportRequest | where {$_.status -eq "Failed"} | Remove-MailboxExportRequest

Ran the above requests and they behaved as expected.  I confirmed the requested and the commands executed successfully.  

Thanks.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Are the queues running again?

Author

Commented:
No, nothing is queued.  Everything showed as completed (but the exported mailboxes did not really export, most of them show 265 kb) or as Failed.  Most of the items showed as Completed.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hmm ok. For the bigger experts, can you verify the export is between thr dates specified?

Author

Commented:
Ran the command to do the export again.  Yup, dates are good.  Will see how this one goes.  Thank you.
Patrick BogersDatacenter platform engineer Lindows

Commented:
Nice! Fingers crossed

Author

Commented:
What is seeming to happen is that the folder structure of each mailbox is exported, but none of the emails that are in the folders.   Sad. . .
Commented:
From another forum (Spiceworks):

Switch your less than and greater than

foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -ContentFilter {(Received -lt '02/01/2017') -and (Received -gt '11/21/2016')} -Mailbox $i -Filepath "\\10.10.1.35\EmailBackup\$($i).pst" }

Ran it, and it looks promising so far!
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hi again,

I dont see it, can you explain what is different?

Cheers

Author

Commented:
Switched the greater than and less than dates in the formula.  

FROM:  {(Received -lt '11/21/2016') -and (Received -gt '02/01/2017')}

TO: {(Received -lt '02/01/2017') -and (Received -gt '11/21/2016')}
Patrick BogersDatacenter platform engineer Lindows

Commented:
Hahaha Nice slipup! Sorry....

Author

Commented:
It is working!  Thank you for your help.
Patrick BogersDatacenter platform engineer Lindows

Commented:
You are welcome!

Author

Commented:
Fixed final piece to make it work.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial