Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 969
  • Last Modified:

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.
0
j8547
Asked:
j8547
  • 5
  • 4
  • 2
  • +2
1 Solution
 
oBdACommented:
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)?
0
 
ThommyCommented:
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


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

I will try themn out now
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
oBdACommented:
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
0
 
j8547Author Commented:
I am getting the system cannot find the path specified yet the paths look correct. Any ideas???
0
 
oBdACommented:
The closing quotes in the target folder are missing, that could be the issue.
Otherwise, please copy and paste the output of
for /L %i in (1, 1, 20) do @ECHO copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location"
0
 
leakim971PluritechnicianCommented:
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.
0
 
leakim971PluritechnicianCommented:
0
 
symmcomCommented:
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.
0
 
j8547Author Commented:
It was the quotes. Thanks it is working perfectly now.
0
 
j8547Author Commented:
Sorry also does the person have to be an admin or can this script use an admin account?????
0
 
oBdACommented:
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.
0
 
j8547Author Commented:
Thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now