22

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.

Community
  • 1
  • 1
Jay
  • 1,392
  • 7
  • 17
  • 44

4 Answers4

24

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.

Tilo
  • 1,110
  • 3
  • 21
  • 42
16

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
Anvesh Yalamarthy
  • 1,625
  • 20
  • 36
5

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
Maximus
  • 10,751
  • 8
  • 47
  • 65
2

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