Can't copy files to UNC Destinations if BAT file is called via scheduled task

后端 未结 5 1745
无人共我
无人共我 2021-02-02 01:52

I have a bat file copying files from current machine to mapped network drive (one line, xcopy command).

It works when I RDP to server. However, when I run as a schedule

5条回答
  •  暖寄归人
    2021-02-02 02:27

    I had similar issue where I wanted to copy file(s) from a server to hundreds of other servers without mapping a remote drive to my local PC. I didn't have enough drive letters to map hundreds of remote machines to my local PC! I couldn't just map the remote drive and copy.

    I thought I could use copy, xcopy, or robocopy, and specify my creds to the copy command. But none of the copy commands had any options to provide credentials to remote system.

    Thanks to the post above, I was able to create a small batch file where I just loop through my hosts, and keep re-using just one drive mapping for all my hosts.

    Here is my batch file...

    echo @off
    for /F %%j in (pchostslist1.txt) do (
      net use z:\\%%j\c$ /user:domain\myusername mypassword
      mkdir \\%%j\c$\tmp\mynewdir
      xcopy c:\anyfile.txt \\%%j\c$\tmp\mynewdir
      net use z: /delete
    )
    

提交回复
热议问题