RoboCopy PowerShell Script: Part 2
In this second part, I will go over the basics of analyzing the log generated by the RoboCopy command from part 1 in this series as well as send out pertinent information via email.
First, we need to search the RoboCopy log for "error:" or "denied".
This next block of code will analyze the RoboCopy log file and search for "error:" and "denied" words. If it finds either, it will add a log entry that an issue was found. After this check, I have both log files, the one I created, and the RoboCopy log file copied to the backup destination. The next two code blocks could be used together or you may pick and choose what you want.
But now, I want to know what exactly are the issues when I get this report emailed to me. First, the script reviews the RoboCopy log again, but this time it outputs the line that has the keyword to some new variables that I will be adding to the email body later. Then it copies the statistics at the bottom of the RoboCopy log file and modifies it as an HTML table for easier viewing. Yes, I don't have </td>, but this works and doesn't require me to add more code.
Now, all we need to do is add the email portion of this script. To be able to email, you must have an SMTP relay server already configured.
You will get an email similar to this:
The above is basic email HTML formating. It gives me the information I need without having to log into servers, open log files, and search. Now I can just take a few seconds to review the email if there are any issues I need to address. This is a basic script but has many possibilities. Have fun!