Link to home
Start Free TrialLog in
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!
SOLUTION
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands 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
Avatar of skbryan
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!!!!!
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.
Avatar of 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!
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.
Avatar of 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.
Avatar of skbryan

ASKER

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

Thank you.
Which version PS?
$PSVersionTable
Avatar of skbryan

ASKER

PS N:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
SOLUTION
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
Nice find.
I strongly recommend upgrading powershell to 3 or 4.

Awaiting outcome
Avatar of 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.
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.
Avatar of 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).  

User generated image
Screenshot of folder where the export is being dumped (not showing usernames).

User generated image
Is there a way to "goose" the command?  Thank you.
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?
Avatar of 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.
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
Avatar of 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.
Are the queues running again?
Avatar of 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.
Hmm ok. For the bigger experts, can you verify the export is between thr dates specified?
Avatar of skbryan

ASKER

Ran the command to do the export again.  Yup, dates are good.  Will see how this one goes.  Thank you.
Nice! Fingers crossed
Avatar of 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
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
Hi again,

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

Cheers
Avatar of 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')}
Hahaha Nice slipup! Sorry....
Avatar of skbryan

ASKER

It is working!  Thank you for your help.
You are welcome!
Avatar of skbryan

ASKER

Fixed final piece to make it work.