Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Exchange script to copy email from a users inbox for a specific date range?

Looking for a script that will accomplish the following task.

Copy email from a user’s mailbox that meets a specific date. The copy script should only execute based on the effective date plus 60 days. For example, if a daily script started running Oct 1st, no emails will be copied until Nov 30th. So on Nov 30th only emails from Oct 1st will be copied. On Dec 1st emails from Oct 2nd will be copied, so on an so forth.  No emails will be copied prior to the start date, so if the script starts running on Oct 1st, we can't copy any emails from Sept 30th.  

We would like to copy email from all mail folders except deleted items. We are currently running Exchange 2013.

Basically:  Copy email to "resource.pst" if Date = Current Date + 60 days

Is there are script or software that anyone can think of that can accomplish this task? Please let me know if there are any additional information that I need to provide or if I need to clarify anything.  Thank you.
0
Aaron Margerum
Asked:
Aaron Margerum
  • 6
  • 4
  • 3
2 Solutions
 
Alexei Kuznetsov (Outlook MVP)CEOCommented:
Copy email to "resource.pst" if Date = Current Date + 60 days
But Current Date + 60 days is always in the future! Please provide clarifications. For example, how many dates take place in this script? CurrentDate = Now, StartDate = X, ...?
0
 
Aaron MargerumAuthor Commented:
Thank you for catching that, Alexei Kuznetsov I meant to type - 60.

The purpose of this script would be for archiving and accountability purposes.   The script will only be ran against certain users in a specially created group.  Users will be added and removed from the group as requested.  There will be a start date of when the script will start running.  Once the script starts running, only emails 60 days older than the Start date will be copied.  No emails can be copied from before the start date,  So if the daily script starts running on Oct 1st and User A is added on Oct 1st, the script will run daily but not actually start copying emails until Dec 1st.  Whereas is if User B is added on Dec 31st, the script will immediately start copying emails from Nov 1st.   The script would not go back and copy emails from Oct 1st.

Ideally the script would run on a nightly basis.   So we'd be concerned with the initial kick off date and items that are 60 days older than the current date, but not older than the kick off date.

I hope this clarifies things a little more.  Please let me know.
0
 
Alexei Kuznetsov (Outlook MVP)CEOCommented:
So, the script would copy (for a given User): all emails from specified StartDate to CurrentDate-60days, right? But you'll get duplicate emails each time you run the script because StartDate if fixed. CurrentDate will move to the future from day to day and you'll get dupes from StartDate to CurrentDate-1day (if run the script daily).
0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 
Todd NelsonSystems EngineerCommented:
What version of Exchange?

If Exchange 2010 or newer, take a look at New-MailboxExportRequest and this reference.
0
 
Aaron MargerumAuthor Commented:
Alexei Thank you for your response.  I don't believe that there would be any duplicates because the script would only copy items older than 59 days and younger than 61. So in essence if the requested start date is Oct 24th, The script wouldn't actually start copying emails until Dec 23rd and it would only copy emails dated Oct 24th. Then on Dec 24th it would copy emails dated Oct 25th. On Dec 25th, it would copy emails dated Oct 26t, etc.  If it's not possible to have a fixed date where we say , don't copy any emails before Oct 24th, then we'd just start running the script 60 days after the Oct 24th to avoid copying any emails prior to the start date.( I hope that makes more sense)
0
 
Aaron MargerumAuthor Commented:
Todd, we are running Exchange 2013 CU 7.  Thank you for the links, I will take a look at them this evening.
0
 
Alexei Kuznetsov (Outlook MVP)CEOCommented:
Hmm. So, you only want to export mails for one day that is 60 days before the current day?
0
 
Aaron MargerumAuthor Commented:
Todd thank you again for those links. I've seen the 2nd one.  I think that would be good if I we were doing a one time move for specific dates.  This needs to be ran on a daily basis with different variables.  If there were some way to add add the age variable instead of a date range, I think that could work.

The code from that site is as followed

New-MailboxExportRequest -ContentFilter {(Received -lt '04/01/2010') -and (Received -gt '03/01/2010')} -Mailbox "Pelton" -Name DPeltonExp -FilePath \\ExServer1\Imports\DPelton.pst

I'm in no way a scripting guru. I found this script below that looks like if it can be tweaked and merged the with the previous  script  may give me what I need:  ( May need to add the ExcludeFolders paramenter so it doenst copy things like calanedar, tasks, etc.)

$today=(get-date).adddays(-60)
$users = (Get-Content C:\Users\e003165\scripts\users\60DayOldMsgs\users.txt) <---- Amend path as needed.

foreach ($user in $users){
search-mailbox -identity $user -targetmailbox 'mbexportacct' -targetfolder 'Inbox' -searchquery "Received:< $($today)" |


I hope that I'm on the right track.  Open to anyone's thoughts.
0
 
Aaron MargerumAuthor Commented:
Alexei, yes that is correct.  I know it sounds like an odd request but that is the request we received.
0
 
Alexei Kuznetsov (Outlook MVP)CEOCommented:
This is how you can do that using ReliefJet Essentials Professional Edition with one command:
ExecutorCli.exe /p Profile=Outlook /p Mailbox=@"C:\Test\Users.txt" /u OutlookItemsExportPST For="{INBOX}*" TargetFile="C:\Test\{MAILBOX#EMAIL}.pst" StartDate=-60D EndDate=-60D

Open in new window

This command exports emails from Inbox and all its subfolders for each user listed in C:\Test\Users.txt file (one per line) to C:\Test\<useremail>.pst file. Of course, only emails 60 days before the actual current date. And you can run this command from any computer with Outlook installed, you only need to have FullAccess permissions on mailboxes listed in Users.txt file.
Please note, that I'm one of the developers of the mentioned product.
0
 
Todd NelsonSystems EngineerCommented:
You could modify the command to export the last 60 days based on the date the command is being run...

New-MailboxExportRequest -ContentFilter { Received -ge (Get-Date).AddDays(-60) } -Mailbox "Pelton" -Name DPeltonExp -FilePath \\ExServer1\Imports\DPelton.pst

Open in new window

0
 
Aaron MargerumAuthor Commented:
Thank you Alexei and Todd so much for your assistance in working through this solution.  I am going to hand this information over to my Messaging team so that they can try it out in their test environment.  I will post the results as soon as I hear back.  I wont abandon this solution.  Again, I really appreciate your help.
0
 
Todd NelsonSystems EngineerCommented:
Aaron, can you give us an update of your progress and award as appropriate?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now