Exchange 2013 Export/Delete

I'm looking for two powershell commands for a client of mine. Here are their requirements.

1. Mass export of all mailboxes from Exchange 2013 to PST with aggressive error detection
2. Mass delete all contents from mailboxes within date range without touching contacts and calendars
TheNetworkPro15Asked:
Who is Participating?

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

x
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.

Will SzymkowskiSenior Solution ArchitectCommented:
You need to assign the Import/Export role assignment to a group or a user.

Assign Import Export Role to a Group.
New-ManagementRoleAssignment -Name "Import Export_Enterprise Support" -SecurityGroup "Enterprise Support" -Role "Mailbox Import Export"

Open in new window


Mass Export of All Mailboxes from Exchange 2013
$Mailboxes = Get-Mailbox -ResultSize "unlimited"
ForEach ($Mailbox in $Mailboxes) {
New-MailboxExportRequest -Mailbox $Mailbox -FilePath \\server\sharename\$mailbox.pst
}

Open in new window


Search Mailboxes and Delete Content older than 1 year.
$Date = Get-Date
Get-Mailbox -ResultSize "unlimited" | Search-Mailbox -StartDate $date -EndDate $date.adddays(-365) -DeleteContent

Open in new window


The script above will get all mailboxes and then search the mailboxes for all messages that are between Todays Date ($date) and Todays Date -365 (1 year old) and delete the content. You can adjust these settings based on your requirements.

Will.
0
TheNetworkPro15Author Commented:
Thank you for this. I have one more request..Can you change the delete script to allow defining beginning and end dates?
0
Will SzymkowskiSenior Solution ArchitectCommented:
I have modified the original delete script.

$startdate = (read-host "type start date format: mm/dd/yyyy)
$enddate = (read-host "type end date format: mm/dd/yyyy)
Get-Mailbox -ResultSize "unlimited" |
Search-Mailbox -StartDate $startdate -EndDate $enddate -DeleteContent

Open in new window


When you run this script it will prompt you to enter the start and end dates first and then the script will run using those date values.

Just run the script as is. Do not change the start and end dates in the script as it will prompt you for those values when you run it. The values in the script for read host just give you an example, so just leave them.

Will.
0

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
TheNetworkPro15Author Commented:
Excellent! Thank you for your expert assistance.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Not a problem, glad to help!

Will.
0
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
Powershell

From novice to tech pro — start learning today.