Solved

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

Posted on 2009-07-15
5
249 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 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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