Link to home
Start Free TrialLog in
Avatar of Frank_Day
Frank_DayFlag for United States of America

asked on

Export Mail by Date Range to PST then Delete

I need help with a Powershell script.
I have Exchange Server 2007 sp3. with 30+ mailboxes.
I have installed the Exchange Tools on a Windows 7 32-bit workstation.

I would like to export select single mailboxes to pst files, including all folders and subfolders by date range for archival purposes, THEN Remove/Delete that same date range from their Mailbox.

What would the correct syntax be for this?

I'm successfully using the following to export by date range.  I just don't know how to make it delete upon completion.
Export-Mailbox -Identity <mailbox-alias> -StartDate "01/01/2014" -EndDate "03/31/2014" -PSTFolderPath c:\pstfile
ASKER CERTIFIED SOLUTION
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank_Day

ASKER

I've seen -deletecontent but I'm confused on how to use it.  It seems to always be in context with attachments, subject headings, etc.

If used as you have typed, would it only delete the date range previously stated?  Or does it need further input?

As you may have guessed, I know NOTHING about scripting.
Im on 2010 so I cant test for you but yes this should only delete the messages that match the criteria specified in the command.

That being said test, test, test before you put into action.
The -deletecontent switch might only work if you use the -targetmailbox and -targetfolder switches. At least, that seems to be how the description of the switch is worded. But definitely test it out :D
UpDate, It Worked !

Export-Mailbox -Identity <mailbox-alias> -StartDate "01/01/2014" -EndDate "03/31/2014" -PSTFolderPath c:\pstfile  -deletecontent

This did in fact Export and then Delete all the folders and subfolders within the given date range ONLY.
You can export the items and then delete them by using following command:

Export-Mailbox -marshal@test.local -StartDate "01/01/2014" -EndDate "03/31/2014"” -PSTFolderPath C:\Backup\marshal.pst -deletecontent

Open in new window


Above command will export all items from all folders which are dated from 01/01/2014 to 03/31/2014 and will export them to a PST and delete them from the mailbox.

There are a few other export options:
 
  1. Specific keywords in the subject -SubjectKeywords
  2. Specific keywords in the content –ContentKeywords
  3. Specific folder -IncludeFolders ‘\Sent Items’
  4. Specific attachment name or extension-AttachmentFilenames

Alternatively, you can also use Stellar EDB to PST Converter to export selected items for a particular date range.  For free demo version, check this link: https://www.stellarinfo.com/email-repair/edb-pst-converter.php

User generated image