Solved

Exchange 2010 export all messages from one specific sender

Posted on 2015-01-17
30
1,693 Views
Last Modified: 2015-02-05
Hi there,

I want to export all messages sent to and from certain email addresses to a pst. I dont want to delete any messages from mailboxes just export them to a pst.

I found a similar post here http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_27898646.html but the command wont work for 2010 sp3 (sbs2011)

So advice please, as they could be required for a legal case

Thanks
0
Comment
Question by:David
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 12
30 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40555588
Use the following command below to do this for Exchange 2010.

Get-Mailbox -ResultSize Unlimited | New-MailboxExportRequest -ContentFilter {(sender -eq "smtp@domain.com")} -FilePath "\\SERVER\PSTFiles\ExportMessages.PST"

Open in new window


I have not been able to test this but it should do the trick. Just change the smtp address in the script with the sender you are looking for.

Will.
0
 

Author Comment

by:David
ID: 40555719
Im not sure this code worked, i copied some of the errors below

In short i think what has happened is i needed a new pst for each user it found the email address in.

The pst it created was only 800kb big and only included folders, no emails, so maybe it copied all the folders from the first user in the queue that it found the email address in, but no emails ????

 

Name                                           Mailbox                                        Status
----                                           -------                                        ------
MailboxExport                                  domain.local/MyBusiness/Users/SBSUsers/S... Queued
MailboxExport                                   domain.local/MyBusiness/Users/SBSUsers/I... Queued
MailboxExport                                   domain.local/MyBusiness/Users/SBSUsers/A... Queued
MailboxExport                                   domain.local/MyBusiness/Users/SBSUsers/M... Queued
The server or share name specified in the path may be invalid, or the file could be locked.
    + CategoryInfo          : NotSpecified: (9:Int32) [New-MailboxExportRequest], RemotePermanentException
    + FullyQualifiedErrorId : 1D53B743,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest

The server or share name specified in the path may be invalid, or the file could be locked.
    + CategoryInfo          : NotSpecified: (10:Int32) [New-MailboxExportRequest], RemotePermanentException
    + FullyQualifiedErrorId : 1D53B743,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest
0
 
LVL 17

Expert Comment

by:WORKS2011
ID: 40555751
If you have their password I would use Outlook, create a profile and export this way. It's a bit more work than using PowerShell but I've always found by the time you check the pst with Outlook why not begin with it.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:David
ID: 40555757
the thing is we arent 100% sure who has sent or received emails with the email addresses in question
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40555801
In exchange 2010 you need to run the following command below before the script in my first post will work. If you do no have permissions on the mailbox you cannot export the mailbox.

new-ManagementRoleAssignment -Role "Mailbox Import Export" -SecurityGroup "SecurityGroupNameHere"

$Mailbox = Get-Mailbox -ResultSize Unlimited
Foreach ($user in $Mailbox) {
New-MailboxExportRequest -Identity $user -ContentFilter {(sender -eq "smtp@domain.com")} -FilePath "\\SERVER\PSTFiles\$user.pst
}

Open in new window


Will.
0
 

Author Comment

by:David
ID: 40556155
Thanks will, still no luck im afraid. The first script still complains of the file could not be locked?

As for the second script is that to be run directly in EMS?
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40556164
Yes you run this from the EMS. If you want to run it from a regular powershell session you will need to import the Exchange 2010 module.

add-pssnapin microsoft.exchange.management.powershell.E2010

Will.
0
 

Author Comment

by:David
ID: 40556193
i was just struggling with the last code thats why i asked. Ive entered the code all onto one line and get the following

Unexpected token 'in' in expression or statement.
At line:1 char:63
+ $Mailbox = Get-Mailbox -ResultSize Unlimited Foreach ($user in <<<<  $Mailbox) {New-MailboxExportRequest -Identity $u
ser -ContentFilter {(sender -eq "dd@mydomain.com")} -FilePath "\\WSDC01\export\$user.PST"}
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
 

Author Comment

by:David
ID: 40556197
this is why i typed [PS] C:\Windows\system32>$Mailbox = Get-Mailbox -ResultSize Unlimited Foreach ($user in $Mailbox) {New-MailboxExportRequest -Identity $user -ContentFilter {(sender -eq "dd@mydomain.com")} -FilePath "\\WSDC01\export\$user.PST"}
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40556284
It appears that the variable is not being created. Can you open the EMS and type the first line $mailbox = get-mailbox -resultsize unlimited (press enter)

Type $mailbox (press enter) see if you get all of the mailboxes are results.

If $mailbox gives you all of the mailbox results then run the rest of the command.

foreach ($user in $mailbox) { .........

The above error message you are getting appears that it does not like the variable.

Will.
0
 

Author Comment

by:David
ID: 40556380
I ran the foreach ($user

and the following message came up for each user

A positional parameter cannot be found that accepts argument 'Discovery Search Mailbox'.
    + CategoryInfo          : InvalidArgument: (:) [New-MailboxExportRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-MailboxExportRequest
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40558872
Did you assign the proper role permissions for the user you are using to export the mailbox? I posted this in a few previous comments. New-managementroleassignment ....

Will.
0
 

Author Comment

by:David
ID: 40559541
I create a group for my account called "Export user" and ran

new-ManagementRoleAssignment -Role "Mailbox Import Export" -SecurityGroup "Export user"

Or should i run it exactly as you wrote

new-ManagementRoleAssignment -Role "Mailbox Import Export" -SecurityGroup "SecurityGroupNameHere" ???
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40560495
No the way you did it is fine, you need to add your security group in there "SecurityGroupNameHere".

I will test the script above in my lab. I have not tested this.

Will.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40560582
I have just tested this in my lab and I did not have the proper syntax for the New-MailboxExportRequest cmdlet. I had -identity when it should be -Mailbox. I have since tested this and it works as expected. Creating all individual pst files.

$Mailbox = Get-Mailbox -ResultSize Unlimited
Foreach ($user in $Mailbox) {
New-MailboxExportRequest -Mailbox $user -ContentFilter {(sender -eq "smtp@domain.com")} -FilePath "\\SERVER\ShareName\$user.pst
}

Open in new window

That should do it.

Will.
0
 

Author Comment

by:David
ID: 40560728
Hi Will

Partial success. I have to run it line by line, it created a new pst for each user, it also exported all the users folders. But it didnt export any emails in any of the folders. Any ideas?
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40561010
You should not have to run this line by line. Copy and paste the script into notepad and save it as .ps1 file extension. Then run the script.ps1 in the management shell. This should work for you.

As for the export It has to export all of the individual mailboxes regardless if it finds anything. It creates the entire mail structure and then from there will place any of the mail items in the folders where it found them in the source mailbox.

Will.
0
 

Author Comment

by:David
ID: 40568475
Hi Will i think im missing something obvious here so appologies in advance

when i run the script i get the following

[PS] D:\>export.ps1
The term 'export.ps1' 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:11
+ export.ps1 <<<<
    + CategoryInfo          : ObjectNotFound: (export.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40568482
Based on your Windows Environment Variables you might have to be in the exact path where the script file is located. This is usually found the your Windows Path under environment varibale is set to c:\ rather than %systemroot% (variable).

When you go to the directory where the script is located you need to run the script using .\export.ps1.

Will.
0
 

Author Comment

by:David
ID: 40568505
Sorry my mistake i had a typo for the script filename.

The script ran but again the exported users only had folders and no emails exported, any ideas?
0
 

Author Comment

by:David
ID: 40569582
Im not sure what else to try on this one?
0
 

Author Comment

by:David
ID: 40571369
Hi Will did you test actually export mails as well?
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40571387
Yes this has worked in my lab environment.

Will.
0
 

Author Comment

by:David
ID: 40571425
Any ideas what i may of missed ?
0
 

Author Comment

by:David
ID: 40573760
Does anyone have any other suggestions please? I feel we are more than half way there!!
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 total points
ID: 40573765
Have you tried it as a single command to ensure that it is exporting the data correctly?

New-MailboxExportRequest -Mailbox <username> -ContentFilter {(sender -eq "smtp@domain.com")} -FilePath "\\SERVER\ShareName\user.pst

Open in new window


See if this code works for you without doing it for all accounts. Like i said if the script cannot find any messages from this user it will not  have any items in it.

Will.
0
 

Assisted Solution

by:David
David earned 0 total points
ID: 40574045
I think ive cracked it, obviously your help will has been invaluable but this link also helped https://social.technet.microsoft.com/forums/exchange/en-US/4cf4f468-3554-43aa-b3ca-6a95e9ee1df5/mailboxexportrequest-contentfilter-query

in short i changed the filter from sender to all and used wildcard which also allowed the sent items to be searched properly

{All -like "*user@hotmail.com*"}

ill confirm once all the mailboxes have completed which may be a few hours
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40574049
Glad that you figured it out!

Will.
0
 

Author Comment

by:David
ID: 40581766
worked perfectly

Thanks

David
0
 

Author Closing Comment

by:David
ID: 40590662
guided me to the solution
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question