Solved

AD Script to Move computer from default to a new OU

Posted on 2008-10-31
7
620 Views
Last Modified: 2009-05-05
I found this code that someone provided that will move users or computers from one OU to another OU and it works fine. However I have a client that needs to move computers from the default location (CN=Computers) to a new OU
I have attached the code.
Option Explicit
'On Error Resume Next
Dim aConnection, aCommand, aResult, strResultText, strDN, dtmValue, objComputer, objOU, fso, strLine, objFile, strFilePath, strNewLDAP
strFilePath = "C:\userlist.txt"
Set fso = CreateObject("Scripting.Filesystemobject")
Set objFile = fso.OpenTextFile(strFilePath, 1)
strNewLDAP = InputBox("Enter the LDAP name of target OU:")
 
Set aConnection = CreateObject("ADODB.Connection")
Set aCommand = CreateObject("ADODB.Command")
aConnection.Provider = "ADsDSOObject"
aConnection.Open
aCommand.ActiveConnection = aConnection
Set objOU = GetObject("LDAP://" & strNewLDAP)
 
Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine
	objOU.MoveHere "LDAP://" & strLine, vbNullString
Loop
 
objFile.Close

Open in new window

0
Comment
Question by:g-techforce
  • 4
  • 3
7 Comments
 

Author Comment

by:g-techforce
ID: 22853291
The command i run to get the c:\userlist is:

dsquery computer CN=Computers,dc=domain,dc=com >> C:\userlist.txt

and it creates a file called userlist with the following example inside:

"CN=shanana,CN=Computers,DC=brad,DC=local"
"CN=miley,CN=Computers,DC=brad,DC=local"
0
 
LVL 18

Expert Comment

by:sk_raja_raja
ID: 22853541
0
 
LVL 18

Expert Comment

by:sk_raja_raja
ID: 22853545
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:g-techforce
ID: 22854086
id rather use the code i have and just modify it to work.
Anyone know what I need to change to get it to work?
0
 
LVL 18

Expert Comment

by:sk_raja_raja
ID: 22854298
1)Apply following commands to it will MOVE  **ALL**  COMPUTER TO NEW OU.
You need to change OU DN in 2nd statement.

Click Start -> Run -> Cmd.exe

DSQuery Computer -Name * -Limit 0 >Computers.txt

FOR /F "delims=*" %c IN ('Type Computers.txt') DO DSMove  %c -newparent "OU=SALES,DC=TRAINING,DC=COM

2)Try Dsmove.exe. Here's a link for more information:
http://support.microsoft.com/kb/298882

3)http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23454736.html
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21605648.html
0
 

Author Comment

by:g-techforce
ID: 22901899
ok i misunderstood the client.
I need some sort of script that when a user logs into the domain successfully it will check to see if he's in the correct OU.

Is there a login script or something that can move a computer to another OU if the user logs in successsfully?
0
 

Accepted Solution

by:
g-techforce earned 0 total points
ID: 22927202
Ok,
here is an update. Apparently I misundertood him again, but this time its simple.

I need a script he can run from a login script that will take that particular computer and move it to the new OU.

for example
Jane's computer is in the default OU. Jane logs into the domain and the script runs and moves only HER computer to the NEW Ou.

sounds simple but i cant find the code to do it.
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

Title # Comments Views Activity
passing parameter in sql procedure 9 63
using web browser with BING 40 122
Error when passing an argument to a vb6 that contains  '/' 7 38
VBA Shell can't Find Word document 11 95
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 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