Solved

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

Posted on 2016-10-24
13
90 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 14

Expert Comment

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

Expert Comment

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

 
LVL 14

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 14

Expert Comment

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

Accepted Solution

by:
Alexei Kuznetsov earned 250 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 14

Assisted Solution

by:Todd Nelson
Todd Nelson earned 250 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 14

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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