Link to home
Create AccountLog in
Exchange

Exchange

--

Questions

--

Followers

Top Experts

Avatar of David
David

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 https://www.experts-exchange.com/questions/27898646/Exchange-2007-export-all-messages-from-one-specific-sender.html but the command wont work for 2010 sp3 (sbs2011)

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

Thanks

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Will SzymkowskiWill Szymkowski🇨🇦

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.

Avatar of DavidDavid

ASKER

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

Avatar of WORKS2020WORKS2020🇺🇸

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.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of DavidDavid

ASKER

the thing is we arent 100% sure who has sent or received emails with the email addresses in question

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.

Avatar of DavidDavid

ASKER

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?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


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.

Avatar of DavidDavid

ASKER

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

Avatar of DavidDavid

ASKER

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"}

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


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.

Avatar of DavidDavid

ASKER

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

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.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of DavidDavid

ASKER

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

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.

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.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of DavidDavid

ASKER

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?

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.

Avatar of DavidDavid

ASKER

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

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


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.

Avatar of DavidDavid

ASKER

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?

Avatar of DavidDavid

ASKER

Im not sure what else to try on this one?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of DavidDavid

ASKER

Hi Will did you test actually export mails as well?

Yes this has worked in my lab environment.

Will.

Avatar of DavidDavid

ASKER

Any ideas what i may of missed ?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of DavidDavid

ASKER

Does anyone have any other suggestions please? I feel we are more than half way there!!

ASKER CERTIFIED SOLUTION
Avatar of Will SzymkowskiWill Szymkowski🇨🇦

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

SOLUTION
Avatar of DavidDavid

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Glad that you figured it out!

Will.

Avatar of DavidDavid

ASKER

worked perfectly

Thanks

David

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of DavidDavid

ASKER

guided me to the solution
Exchange

Exchange

--

Questions

--

Followers

Top Experts

Exchange is the server side of a collaborative application product that is part of the Microsoft Server infrastructure. Exchange's major features include email, calendaring, contacts and tasks, support for mobile and web-based access to information, and support for data storage.