Robocopy - Monitor with Email Reporting

I have a server in NY and one in London.
I have set up a folder in NY so when a user drops a file into it, it moves it to a folder on the server in London. I have done this using Robocopy and I am  happy with it.
It is using the MOT switch and is constantly running.

I would like to add some kind of email functionality so that when a file has been sucessfully copied a notification is sent to specified users.

I have managed to do this with a batch file running a single Robocopy instance and calling a PowerShell command after. But as this works by running after robocopy it does not suit my needs. I need it to run after a file has been succesffuly copied

I run this batch file
-----------------------------------------------------
Robocopy "\\NYServer\Folder1" "\\LondonSever\Folder1" /E /Z /MOT:2 /MOVE /R:20"

Powershell.exe C:\Robocopy\Email.ps1
-------------------------------------------------------




This is  Powershell Email.ps1
-------------------------------------------------------
$emailFrom ="user@domain.co.uk"

$emailTo = "user@domain.co.uk"

$subject = "Test"

$body = "New file in folder"

$smtpserver = "smtp.domain.co.uk"

$smtp = new-object Net.Mail.smtpClient($smtpServer)

$smtp.send($emailfrom, $emailTo, $subject, $body)


 I hope this is enough information for you to help me.




00831607020Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

larsrohrCommented:
Since robocopy is running continuously with MOT, you never get to the powershell command, of course.

You might try running robocopy with a logging option, e.g.
  Robocopy "\\NYServer\Folder1" "\\LondonSever\Folder1" /E /Z /MOT:2 /MOVE /R:20 /LOG:C:\robolog.txt
(I don't know, though, does robocopy append to the log in this case when run with /MOT, or will it potentially overwrite the log every 2 minutes?)

... and then running a separate continuous Powershell script that monitors C:\robolog.txt for changes/additions, and sends your email when appropriate.
I don't have a specific powershell script to do this, but the file monitoring script discussed on the following page may provide inspiration:
 http://gallery.technet.microsoft.com/ScriptCenter/en-us/ed188912-1a20-4be9-ae4f-8ac46cf2aae4


Depending on how robocopy does logging in /MOT mode, and how successfully a powershell script monitors the logfile, you may want to use /LOG+:C:\robolog.txt  (specify append mode).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
00831607020Author Commented:
Sorry for not  getting back to this.... Holiday, busy, etc, etc.
Thank you for the response, I will aim to get round to trying your suggestion this week.
0
00831607020Author Commented:
Sorry I did not respond to this, but other tasks took over and it got left behind.
I hope to revisit this one timem though and will report back if I get an answer.
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.