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

x
?
Solved

Move Computers from Excel list to OU

Posted on 2014-03-18
2
Medium Priority
?
321 Views
Last Modified: 2014-03-19
I need your expertise in scripting. I have a EXCEL file that would include about 200 computers and new OU location where I would like the computers to be moved to.


HOSTNAME      NEWLOCATION
GHSSOC01      OU=SSO-Type1,OU=MHG,OU=Workstations,DC=TESTDOMAIN,DC=local
GHSSOC02      OU=SSO-Type1,OU=MHG,OU=Workstations,DC=TESTDOMAIN,DC=local
GHSSOC03      OU=SSO-Type2,OU=MHG,OU=Workstations,DC=TESTDOMAIN,DC=local

I would like to run a script the morning of implemintation that would move the above computers to their perspective OU.
0
Comment
Question by:epicazo
2 Comments
 
LVL 19

Accepted Solution

by:
helpfinder earned 2000 total points
ID: 39937575
check thisVisual basic script:
on error resume next 
 
CONST ForReading = 1 
Const ForAppending = 8 
 
Set oFS = CreateObject("Scripting.FileSystemObject") 
Set oTS = oFS.OpenTextFile("oldcomputers.txt",ForReading) 
set oLS = oFS.OpenTextFile("movecomputerlog.txt",ForAppending,True) 
Set objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("defaultNamingContext") 
Set objCommand = CreateObject("ADODB.Command") 
Set objConnection = CreateObject("ADODB.Connection") 
objConnection.Provider = "ADsDSOObject" 
objConnection.Open "Active Directory Provider" 
objCommand.ActiveConnection = objConnection 
 
'Modify the following line to desired OU 
Set objNewOU = GetObject("LDAP://OU=Disabled Computers,dc=test,dc=local") 
Do Until oTS.AtEndOfStream 
        strComputer = oTS.ReadLine 
        strQuery = _ 
          "<LDAP://" & strDNSDomain & ">;(&(objectCategory=computer)(cn=" & strComputer & "));adspath,cn;subtree" 
        objCommand.CommandText = strQuery 
        Set RS = objCommand.Execute 
        While not RS.EOF 
                strPath = RS.Fields("adspath") 
                strName = "CN=" & RS.Fields("cn") 
                oLS.Writeline(strPath) 
                Set objMoveComputer = objNewOU.MoveHere(strPath,strName) 
                RS.MoveNext 
        Wend 
Loop 

Open in new window


Source
0
 

Author Closing Comment

by:epicazo
ID: 39939993
Thanks a lot.. works like a charm!
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.

Question has a verified solution.

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

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

877 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