Create a PS script

I am running Exchange 2010

I need to create a Powershell script that will let me get all email from the following domain and save it to a .pst file, can someone help me?
Apollo SmartIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Krzysztof KubiakWindows Server AdministratorCommented:

It's not quite clear what you mean that you want extract all emails from a domain and put it into a pst file?

Do you want to export all emails from all mailboxes into one PST file or do you want to create for each export a seperate PST file?

In general you can achieve exporting mails using the cmdlet:

like this
New-MailboxExportRequest -Mailbox testmailbox -FilePath "\\servername\PSTFileShare\testmailbox.pst"

Before you can use the Mailbox Xport requirst cmdlet you need to assign the account which will run the command proper permission

But there is no option where you can say export all emails from all users on a domain to a PST file.

What exactly do you want to achieve?
How large is your Exchange and how many mailboxes do you have?

A example script you can expand and modify would be something like that (I don't have now in front of me Exchange shell so not sure if all cmdlets will be correct):

Export first all mailboxes to a csv file so you cam modify the csv file in case something go missing or something needs to be removed
Get-Mailbox -Server Mailbox01 | export-csv "Csvpath\csvname"

From the CSV copy out the mailboxnames and save into a new csv with the header MailboxName

Use then something like

$CSVFile = import-csv "Location\nameofCSV"

foreach ($Mailbox in $CSVFile){

New-MailboxExportRequest -Mailbox $Mailbox -FilePath "\\servername\PSTFileShare\mailboxname.pst"


But before you do such thing like you need to do testing, and you need to review your infrastructure if it does make send to do such thing.
If you Exchange environment is large then I definitely not suggest to do it this way as this can take you days or weeks to finish.
When you run the New-MailboxExportRequest against a lot of mailboxes what exchange only does it creates the Export Request, but it does the Export only in limited numbers (I thing default was 5) the rest will be queued.

If you are looking at Migrating your Exchange environment maybe tools like this will help:

It's very hard to help you as your question is very generic and we would need to know more what you are trying to achieve.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Apollo SmartIT ManagerAuthor Commented:
I am trying to export all emails sent and received from a particular domain
the domain is
Hi Apollo,

Where are the emails currently stored?


Apollo SmartIT ManagerAuthor Commented:
Thank you everyone. I was able to create a script and it worked

Here is the script that worked

$Export = get-mailbox; $Export|%{$_|New-MailboxExportRequest -FilePath "\\wiki\pstHYPERLINK "file://wwn/pst/$($_.alias).pst"\$($_.alias).pst" -ContentFilter {All -like '*'} }
Best answer I think.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.