I have created a PowerShell script that is designed to connect to remote application servers, create a zip archive containing the server's application backup and then Robocopy the zip file back to my file server. There are 53 servers listed in a CSV and the script is working perfectly when run manually. The application backups are correctly zipped on the application servers, the zip files are correctly RoboCopied back to my file server, perfect!
Logic of script is as follows:
Import Server List From CSV
Using a ForEach Loop to :
Invoke-Command against each server in list to Zip up the days application backup on the application server
Create source and destination variables
Initiate Robocopy operation along the lines of -
RoboCopy $copysource $copydestination /MAXAGE:1 /MOV /LOG+:$copylog
The issue arises when the script is called by a Scheduled Task. The RoboCopy operation starts and the zip files begin to copy over the network, however, looking at the RoboCopy log, it just stops at anywhere between 1% or sometimes up to 40%. The scheduled task shows has having completed, but it is abandoning the RoboCopy operation mid copy without generating any error codes.
I have tried all the usual options on the scheduled task, such as running with highest privileges etc, but it clearly isn't a permission thing as it does get some of the way through the copy. It almost feels as though the job is timing out, but I've cleared the "Stop the task if it runs longer than:" setting and it is stopping after only a few minutes, certainly not a few days.