Solved

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

Posted on 2016-10-24
13
37 Views
Last Modified: 2016-11-30
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
Comment
Question by:Aaron Margerum
  • 6
  • 4
  • 3
13 Comments
 
LVL 13

Expert Comment

by:Alexei Kuznetsov
Comment Utility
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
 

Author Comment

by:Aaron Margerum
Comment Utility
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
 
LVL 13

Expert Comment

by:Alexei Kuznetsov
Comment Utility
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
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
What version of Exchange?

If Exchange 2010 or newer, take a look at New-MailboxExportRequest and this reference.
0
 

Author Comment

by:Aaron Margerum
Comment Utility
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
 

Author Comment

by:Aaron Margerum
Comment Utility
Todd, we are running Exchange 2013 CU 7.  Thank you for the links, I will take a look at them this evening.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 13

Expert Comment

by:Alexei Kuznetsov
Comment Utility
Hmm. So, you only want to export mails for one day that is 60 days before the current day?
0
 

Author Comment

by:Aaron Margerum
Comment Utility
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
 

Author Comment

by:Aaron Margerum
Comment Utility
Alexei, yes that is correct.  I know it sounds like an odd request but that is the request we received.
0
 
LVL 13

Accepted Solution

by:
Alexei Kuznetsov earned 250 total points
Comment Utility
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
 
LVL 14

Assisted Solution

by:Todd Nelson
Todd Nelson earned 250 total points
Comment Utility
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
 

Author Comment

by:Aaron Margerum
Comment Utility
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
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
Aaron, can you give us an update of your progress and award as appropriate?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now