Solved

Move Computers from Excel list to OU

Posted on 2014-03-18
2
313 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 500 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

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

Suggested Solutions

Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

831 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