Yesterday, I was asked to export all Exchange mailboxes of all employees, whose last name begins with a ‘d’, to PST files.
While this is a very common request, and not difficult at all, an extra requirement was the filename had to be the email address. E.q. john.denver@contoso.com.pst
As a reminder for myself, and anyone who’s interested, here’s what I did:
Firstly, I need to filter all mailboxes of people with last name “D*”. Because get-mailbox doesn’t contain a last name field (it can only give me the alias and displayname), I have to use the get-recipient cmdlet first, and then pipe it to a get-mailbox cmldet
$mailboxes = get-recipient -RecipientType UserMailbox -Filter {lastname -like 'd*'} | ` get-mailbox
$mailboxes now contains all mailboxes to be exported
Because I want to create a separate PST for every individual mailbox, I use a ForEach loop. In addition, I also need the Primary Email address of each mailbox. A mailbox has an attribute PrimarySMTPAddress, but this can contain multiple values. I can use .ToString() to convert the value to a string.
Foreach($mailbox in $mailboxes){ $mailboxname = $mailbox.name $emailaddress = $mailbox.PrimarySmtpAddress.ToString() New-MailboxExportRequest -Mailbox "$mailboxname" ` -Name “ExportD-$mailboxname” ` -FilePath “\\myserver\myshare\$emailaddress.pst” }
To comply with a specific time range, I could add the parameter -ContentFilter
For example, to export all emails BEFORE January 1st 2015:
New-MailboxExportRequest -ContentFilter {(Received -lt '01/01/2015')} ` -Mailbox "$mailboxname" ` -Name “ExportD-$mailboxname” ` -FilePath “\\myserver\myshare\$emailaddress.pst”
Note that the share must be accesible (Modify rights) for the Exchange Trusted Subsystem account. If this account does not have appropriate rights, you will receive the following error:
Unable to open PST file ‘\\servername\share\PST\john.denver@mail.com.pst’. Error details: Access
to the path ‘\\servername\share\PST\john.denver@mail.com.pst’ is denied.
+ CategoryInfo : NotSpecified: (0:Int32) [New-MailboxExportRequest], RemotePermanentException
+ FullyQualifiedErrorId : 794F7DC,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest
Excellent!
I wish I thought of that when I was exporting them manually, whilst looking at the progress bar, for hours and hours, to move on to the next mailbox…
Many thanks for future endeavors!
So got tasked with a similar endeavor. this post was a huge help. TNX
[…] first let me start by saying that i got most of this code from this site. had to fork it a bit to get it to read and display full email address. Just wanted to see if i can […]