Link to home
Start Free TrialLog in
Avatar of j8547
j8547

asked on

Copy file script

I need to create to scripts iin a classroom. Both scripts are essentially the same. I need to copy a config file from 1 pc to a location on 20 other pc's. I just wanted to know if I have to copy from source to destination for each pc or if I can have 1 copy from source to multiple destinations. Any ideas would be great.
Avatar of oBdA
oBdA

There are several possibilities to run this in a more or less simple script for all machine.
Easiest one: create a file with the names of the 20 "other" PCs (one name per line), for example MachineFile.txt.
Then run something like this in a command prompt in the directory with the list:
for /f "delims=" %a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%a\C$\Target\Location

If you want to save this as a batch script, double up on the percebt signs:
for /f "delims=" %%a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%%a\C$\Target\Location

There are other possibilities as well. Do the "other" PCs have a consistent, numeric, naming convention (pc01, pc02, ..., pc20)?
You have to call copy for each destination pc by UNC names with hostnames or ips...

copy config.txt \\pc01\c$\configDir\config.txt
...
copy config.txt \\pc20\c$\configDir\config.txt


You can also use ip address:

copy config.txt \\192.168.65.1\c$\configDir\config.txt
...
copy config.txt \\192.168.65.20\c$\configDir\config.txt


Avatar of j8547

ASKER

I can't use IP address but the pc names range from ...b1 to ...b20

I will try themn out now
With these names, you don't even need a machine list. Just use
for /L %i in (1, 1, 20) do copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location
Avatar of j8547

ASKER

I am getting the system cannot find the path specified yet the paths look correct. Any ideas???
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You may create a share folder in the main server, create a file with the twenty computer names and use psexec : http://technet.microsoft.com/en-us/sysinternals/bb896649
to run a copy from all the computer to get the file(s) from the main server.
Assuming you are the administrator and trying to copy the file from the Server to your 20 client computers, simplest form would be:
1. Create a Batch file (anyname.bat)
2. Inside the Batch file type - copy SourceDrive\Thefile.xyz \\ClientPCName\c$\Folder
3. Copy paste this command 19 other times and change the ClientPCName to correct name

This should copy the file to all destination.
Avatar of j8547

ASKER

It was the quotes. Thanks it is working perfectly now.
Avatar of j8547

ASKER

Sorry also does the person have to be an admin or can this script use an admin account?????
Currently, it has to be an admin due to the administrative share.
If you want this to be run by a regular user, it's safest to share the target folder (with Full Access share permissions for Everyone), and give the "copy" user Change permissions on the target folder.
Avatar of j8547

ASKER

Thanks