Solved

Can you copy a folder to all computers in an OU?

Posted on 2009-07-15
5
241 Views
Last Modified: 2012-05-07
This is a question that has been bugging me for some time. I would like to know if there is a way to run a VBScript that would copy a folder to all computers within an OU? I know this can be done with GP, but I would really like to see if it can be done from my machine or server with a script.
0
Comment
Question by:error131
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 24863920
So, for example, on your computer you have a folder called "DistributionSource" on your C: drive, and you want it copied to "C:\DistributionDest" on every computer in a given OU?

I didn't test this, but in theory I think it should work so long as you have admin access to the remote machines.
Option Explicit
 

Dim FileSystem

Dim OU

Dim computer
 

Set FileSystem = CreateObject("Scripting.FileSystemObject")

Set OU = GetObject("LDAP://OU=Computers,DC=yourdomain,DC=com")

OU.Filter = Array("computer")
 

For Each computer in OU

	FileSystem.CopyFolder "C:\DistributionSource", "\\" & computer.Name & "\c$\DistributionDest"

Next

Open in new window

0
 

Author Comment

by:error131
ID: 24864186
That is exactly what I am looking for.
I tried running your script but it says path not found on line 12. I am pretty sure I have it correct, but mabey you know somthing I don't.
0
 

Author Comment

by:error131
ID: 24864346
I see now. It pulls the destination path like this >
\\CN=DAVID-LAURENT\d$\test

0
 

Author Comment

by:error131
ID: 24869385
Well in the end I had to go a little differnt way. But this seems to work great.
Set objOU = GetObject("LDAP://ou=ittestou,dc=domain,dc=com") 

objOU.Filter = Array("computer") 

Set objFSO = CreateObject("Scripting.FileSystemObject") 

For Each objComputer In objOU 

    strNTName = objComputer.sAMAccountName 

         strNTName = Left(strNTName, Len(strNTName) - 1) 

    If (objFSO.FolderExists("\\" & strNTName & "\d$\iaclient") = False) Then 

 objFSO.CopyFolder "\\testserver\applications\interaction\5.6sp2", "\\" & strNTName & "\d$" 

    End If 

Next 

Open in new window

0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 24869940
Sorry...saw your post last night & forgot to respond, but you've got exactly what I would've said anyway!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now