I want to schedule a batch file to execute a command and redirect that output a text file.

This is my current solution:

Del \\\Netbackup_Softwares\Personal\Bharath\VM_Query\switch.txt
D:\VMware_Query\VM_Query.bat >> \\\Netbackup_Softwares\Personal\Bharath\VM_Query\switch.txt

Windows Server 2012

When I tried with task scheduler its executing the command but not redirecting output to text file.

Command works fine when I execute from cmd prompt.

  • can someone help me with this. – user3016638 May 12 '16 at 7:01
  • Can you post the logic which is in your batch file VM_Query.bat? I would put the << %logfilename% in that file and just have the schedule pass the UNC full pass as an argument and then delete if exist and all the rest. Post the batch logic from your file to an edit on your answer and I will show you how to EASILY get this to work and provide an answer with a precise example I test and confirm to work just as you describe. – Pimp Juice IT May 14 '16 at 14:12

Please check the following options in the task scheduler UI,

  • When running the task, use the following user account:
  • Run whether user is logged on or not

And just for troubleshooting, try to schedule the task for once storing the output to a local drive (instead of an UNC path)

Hope this helps.

  • I have the correct checks enabled for the task scheduler UI. I need to redirect this to UNC path instead local disk. Task scheduler runs the command its not redirecting the O/P. – user3016638 May 12 '16 at 3:34
  • @user3016638 - Just to clarify further, if you changed the command (just for troubleshooting) did the task run underschedule was able to write to a local file? – hkdtam May 12 '16 at 3:48
  • I didn't try on local disk but that wont help me – user3016638 May 12 '16 at 4:33
  • @user3016638 - Oh I see. That was only a measure trying to isolate the problem scope. – hkdtam May 12 '16 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.