Jay
Jay

Reputation: 1422

Copy files to network computers on windows command line

I am trying to create a script on Windows which when run on an admin PC:

  1. Copies a folder from the admin PC into a group of network PCs by specifying the ip address / range
  2. For each destination PC, Navigate into the folder and run another script file.

Using the method described by seanyboy here:

net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}

I'm not sure on how i can write a 'for' loop to go through each 'dest-machine' and perform step 2. Any ideas would be greatly appreciated.

Upvotes: 23

Views: 250422

Answers (4)

user4317480
user4317480

Reputation: 31

Regarding step 2., check manual for psexec command (sysinternal tools)

Upvotes: 2

Anvesh Yalamarthy
Anvesh Yalamarthy

Reputation: 1693

Below command will work in command prompt:

copy c:\folder\file.ext \\dest-machine\destfolder /Z /Y

To Copy all files:

copy c:\folder\*.* \\dest-machine\destfolder /Z /Y

Upvotes: 16

Tilo
Tilo

Reputation: 1220

check Robocopy:

ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT

make sure you check what robocopy parameter you want. this is just an example. type robocopy /? in a comandline/powershell on your windows system.

Upvotes: 25

Maximus
Maximus

Reputation: 10845

Why for? What do you want to iterate? Try this.

call :cpy pc-name-1
call :cpy pc-name-2
...

:cpy
net use \\%1\{destfolder} {password} /user:{username}
copy {file} \\%1\{destfolder}
goto :EOF

Upvotes: 5

Related Questions