Solved

Exchange 2010 export all messages from one specific sender

Posted on 2015-01-17
30
1,098 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
  • 17
  • 12
30 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:David
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:David
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Im not sure what else to try on this one?
0
 

Author Comment

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

Expert Comment

by:Will Szymkowski
Comment Utility
Yes this has worked in my lab environment.

Will.
0
 

Author Comment

by:David
Comment Utility
Any ideas what i may of missed ?
0
 

Author Comment

by:David
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad that you figured it out!

Will.
0
 

Author Comment

by:David
Comment Utility
worked perfectly

Thanks

David
0
 

Author Closing Comment

by:David
Comment Utility
guided me to the solution
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Intunes without company portal 3 35
Hide External contact 13 26
Circular Logging 2 25
outlook 3 15
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now