Task Scheduler and PowerShell Sharefile snapin

  • 1
  • Problem
  • Updated 10 months ago
I created a powershell script that syncs a local directory to a share file directory and .bat file that launches that script. When I launch the .bat file from the command line it works perfectly. However, when I try to launch the .bat from a task in task scheduler, the task completes successfully, but the files are never copied. I run the task with the highest privilege.

Any clues to what's happening?

Thanks in advance
Photo of Marcelo Rizzo

Marcelo Rizzo

  • 32 Posts
  • 5 Reply Likes

Posted 10 months ago

  • 1
Photo of Zack Eleveld

Zack Eleveld

  • 22 Posts
  • 4 Reply Likes
There are a few things that you should check because running your script as a batch file is not the same as running it interactively.  
  1. Are all of your environment variables set correctly?  Are your paths referring to the same place or do you have to connect to shared resources.
  2. Have you made sure to include statements to load the sharefile libraries, authenticate your user, etc?
  3. Are you waiting for the sync to finish before exiting the job?  I was scheduling the syncs in multiple sub-jobs and then not waiting for them to finish. The sync was being interrupted by the parent job completing.  I had to make the parent job check to be sure that the sub-jobs were complete before it exited.
If it's not working for you still, try writing something that is simpler.  Just copy a file from one place on your drive to another.   Schedule your task and let it run.  See if your file moved.  Once you can successfully do something locally, then try to automate a small sharefile task (try syncing a single file) and finally automate your whole sharefile task.

Finally, powershell includes its own task scheduling abilities called scheduled jobs.  There isn't a GUI to control them, but you might want to consider using them instead (you will still have to solve your other problems).