Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-10-24
13
Medium Priority
?
199 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 15

Expert Comment

by:Alexei Kuznetsov (Outlook MVP)
ID: 41857163
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
ID: 41857223
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 15

Expert Comment

by:Alexei Kuznetsov (Outlook MVP)
ID: 41857239
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 17

Expert Comment

by:Todd Nelson
ID: 41857287
What version of Exchange?

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

Author Comment

by:Aaron Margerum
ID: 41857472
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
ID: 41857473
Todd, we are running Exchange 2013 CU 7.  Thank you for the links, I will take a look at them this evening.
0
 
LVL 15

Expert Comment

by:Alexei Kuznetsov (Outlook MVP)
ID: 41857506
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
ID: 41857570
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
ID: 41857575
Alexei, yes that is correct.  I know it sounds like an odd request but that is the request we received.
0
 
LVL 15

Accepted Solution

by:
Alexei Kuznetsov (Outlook MVP) earned 1000 total points
ID: 41857603
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 17

Assisted Solution

by:Todd Nelson
Todd Nelson earned 1000 total points
ID: 41857872
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
ID: 41858531
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 17

Expert Comment

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

Featured Post

WatchGuard Case Study: NCR

With business operations for thousands of customers largely depending on the internal systems they support, NCR can’t afford to waste time or money on security products that are anything less than exceptional. That’s why they chose WatchGuard.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Eseutil Hard Recovery is part of exchange tool and ensures Exchange mailbox data recovery when mailbox gets corrupt due to some problem on Exchange server.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

885 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