Solved

Write a bat file that copies files to all computers in an OU

Posted on 2004-09-29
11
214 Views
Last Modified: 2010-04-14
What I would like to do have a bat file I can run either on a domain controller or a file server within my domain that copies a file to all computers within an OU.

The bat file would be run manually and probably not too often, but I don't want to have to go to each machine to get the file on the computer.

Thanks.
0
Comment
Question by:mrichmon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 10

Expert Comment

by:Longbow
ID: 12183142
I would not run a batch file manually to all the computers because
 you never know wich computer have received the files.
If one computer is off your script can stop.

1) You can create a logon .bat script :
@echo off
if not exist c:\destination\filename.ext copy \\server\share\filename.ext c:\destination\filename.ext

2) Another solution would be :
@echo off
regedis /s \\server\share\file2copy.reg
copy \\server\share c:\destination\filename.bat

In filename.bat you have the code found in 1)

in file2copy.reg you have the registry key RunOnce=c:\destination\filename.bat
0
 
LVL 35

Author Comment

by:mrichmon
ID: 12183645
But I do not want this to happen at logon.

I want to run it manually, and immediatley upon running the bat file.
0
 
LVL 18

Expert Comment

by:exx1976
ID: 12184004
Easy.  I would write a piece of VBScript to do this..  Something like:

Set oFS = CreateObject("Scritping.FileSystemObject")
Set oOU = GetObject ("LDAP://OU=<yourOUname>,DC=<yourDomainName>,DC=<TLD>")
For Each computer in oOU
     MachineName = Right(computer.Name, Len(computer.Name)-3)
     oFS.CopyFile "\\server\share\file", "\\" & MachineName & "\share\file"
Next
WScript.Echo("Done.")


HTH,
exx

PS - obviously, it is assumed that all computers listed in the OU are connected to the network and turned on...
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 35

Author Comment

by:mrichmon
ID: 12184870
When I tried that I got the following error:

Line : 1
Char : 1
Error : ActiveX xomponent can't create object: 'Scripting.FileSystemObject'
Code : 800A01AD
Source : Microsoft VBScript runtime error
0
 
LVL 18

Expert Comment

by:exx1976
ID: 12185179
Oops..  Did you cut and paste my script?  I accidentally misspelled scripting...  LOL
0
 
LVL 35

Author Comment

by:mrichmon
ID: 12185282
I'll try again... :o)

I also found that you can have a file that simply has :

copy \\server\share\filename "\\machinename\share\location\"

for each system, but I like the idea that it can be in a for each loop
0
 
LVL 35

Author Comment

by:mrichmon
ID: 12185334
Well that worked for just grabbing the machine name, but when I actually put in the copy line it died when it couldn't access a machine and didn't tell me which machine - nor did it continue on with the rest.

Just putting the copy lines manually into the bat file at least shows a log of what failed and worked and also tries each one regardless of if the last one failed or not.....
0
 
LVL 18

Accepted Solution

by:
exx1976 earned 500 total points
ID: 12189357
Ok, this one will echo for you..  And I fixed the spelling so you can just copy and paste it..

On Error Resume Next
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oOU = GetObject ("LDAP://OU=<yourOUname>,DC=<yourDomainName>,DC=<TLD>")
For Each computer in oOU
     MachineName = Right(computer.Name, Len(computer.Name)-3)
     WScript.Echo("Copying to " & MachineName & ".")
     oFS.CopyFile "\\server\share\file", "\\" & MachineName & "\share\file"
Next
WScript.Echo("Done.")

Alternatively, if you really like the dos copy command, you could use this script:

On Error Resume Next
Set ws = CreateObject("Wscript.Shell")
Set oOU = GetObject("LDAP://OU=<ou>,DC=<domain>,DC=<TLD>")
For Each computer in oOU
     MachineName = Right(computer.Name, Len(computer.Name)-3)
     ws.run("copy \\server\share\file \\" & MachineName & "\share\file >> c:\copylog.txt")
Next
WScript.Echo("Done.")

To the bext of my knowledge, there is no DOS interface to AD that could be used in a regular old batch file..  At least not without the use of third party tools.  But the second script here should do what you want.  It uses the DOS copy command, and pipes the output to a text log so you can review it.

HTH,
exx
0
 
LVL 10

Expert Comment

by:Longbow
ID: 12189486
You can use a network manager like Landesk to put tasks an any computer on your network :
http://www.landesk.com
0
 
LVL 35

Author Comment

by:mrichmon
ID: 12191620
Thanks a lot!
0
 
LVL 18

Expert Comment

by:exx1976
ID: 12191797
n/p
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question