top of page

RoboCopy PowerShell Script: Part 1

Writer's picture: Chris KeimChris Keim

Updated: Nov 2, 2020


In most cases, my RobCopy scripts/commands are run on demand, and I review the results right away. But in some cases, I need to have a RoboCopy script run as a scheduled task. The last thing I want to do is manually check the RoboCopy log, I want the relevant information brought to me, via email so I can lazily read it while drinking my morning coffee.


Yes, I have just attached the log files and sent those out, but there are a couple of issues. One, Those files can get large. You could compress them, but some email systems have issues with zip files. Also, I still have to search the entire log file for issues. I'd rather have the script do it for me and only show me the information I want to see, which is not much. This script will grab the information I want to see in an easy to read format, saving me time.


Below is an example of the email report you can expect to get.



In this series, I will be covering the following:

  1. Building the basic RoboCopy PowerShell script.

  2. Adding error checking with the RoboCopy log file. Emailing of important information so I can spend 5 seconds instead of 5 minutes validating the results of the script.


Here is a very simplistic scenario. And yes, some of the code here could be reduced by using functions. Data needs to be copied from the local server to another server for some purpose at a specific date interval. First, I need to figure out the parameters that must be defined.

Now, I want to start general logging. The first line creates a date/time stamp variable used to append the log file name. Next, the log path is created if it isn't there already. Both log objects are fully defined, the script log file, and the RoboCopy log file. Then finally a log entry is defined and committed to the log file.

At the beginning of all my logs, I like to display the variables that I have defined that are important to me. In this case, I want to log the source and destinations.


Now we finally get to to the RoboCopy area. For specifics on RoboCopy switches, please refer to Microsoft.


In part 2, I will go over automating the review of the RoboCopy log file for issues and emailing out the report.







2,340 views0 comments

Comments


bottom of page