Avatar of skbryan
skbryan
 asked on

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

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!
Exchange* Export

Avatar of undefined
Last Comment
skbryan

8/22/2022 - Mon
SOLUTION
Patrick Bogers

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
skbryan

ASKER
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 Bogers

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.
skbryan

ASKER
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!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Patrick Bogers

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.
skbryan

ASKER
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.
skbryan

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

Thank you.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Patrick Bogers

Which version PS?
$PSVersionTable
skbryan

ASKER
skbryan

ASKER
PS N:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
skbryan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Patrick Bogers

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

Awaiting outcome
skbryan

ASKER
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 Bogers

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
skbryan

ASKER
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 Bogers

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?
skbryan

ASKER
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Patrick Bogers

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
skbryan

ASKER
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 Bogers

Are the queues running again?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
skbryan

ASKER
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 Bogers

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

ASKER
Ran the command to do the export again.  Yup, dates are good.  Will see how this one goes.  Thank you.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Patrick Bogers

Nice! Fingers crossed
skbryan

ASKER
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. . .
ASKER CERTIFIED SOLUTION
skbryan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Patrick Bogers

Hi again,

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

Cheers
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
skbryan

ASKER
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 Bogers

Hahaha Nice slipup! Sorry....
skbryan

ASKER
It is working!  Thank you for your help.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Patrick Bogers

You are welcome!
skbryan

ASKER
Fixed final piece to make it work.