Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2703
  • Last Modified:

Exchange 2010 export all messages from one specific sender

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
David
Asked:
David
  • 17
  • 12
2 Solutions
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
WORKS2011Austin Tech CompanyCommented:
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
DavidAuthor Commented:
the thing is we arent 100% sure who has sent or received emails with the email addresses in question
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
DavidAuthor Commented:
Im not sure what else to try on this one?
0
 
DavidAuthor Commented:
Hi Will did you test actually export mails as well?
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Yes this has worked in my lab environment.

Will.
0
 
DavidAuthor Commented:
Any ideas what i may of missed ?
0
 
DavidAuthor Commented:
Does anyone have any other suggestions please? I feel we are more than half way there!!
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
DavidAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
Glad that you figured it out!

Will.
0
 
DavidAuthor Commented:
worked perfectly

Thanks

David
0
 
DavidAuthor Commented:
guided me to the solution
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 17
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now