Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-15
5
Medium Priority
?
254 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
[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
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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 …
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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