Solved

How to move the user accounts from one OU to another OU by VBScript?

Posted on 2008-06-18
2
1,152 Views
Last Modified: 2008-06-19
Dear all experts,

I would like to implement a VBScript program which is used to move some user / computer accounts from one OU to another, please kindly give me some advise about it.

Regards,
0
Comment
Question by:towo2002
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 21819063
Hi, this article should definately get you started.  If you need anything else, let us know:

How Can I Move a Computer From an Unknown OU into a Known OU?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun06/hey0623.mspx

Where it's got
"AND Name='atl-ws-01'"

you could change that to
"AND Name='" & strComputerName & "'"

and at the top of the script have
strComputerName = InputBox("Enter the name of a computer to move:", "Computer Name")

Regards,

Rob.
On Error Resume Next
 

Const ADS_SCOPE_SUBTREE = 2
 

objOU = GetObject("LDAP://ou=Finance,dc=fabrikam,dc=com")
 

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand =   CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
 

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 

objCommand.CommandText = _

    "SELECT ADsPath FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='computer' " & _

        "AND Name='atl-ws-01'"

Set objRecordSet = objCommand.Execute
 

objRecordSet.MoveFirst
 

Do Until objRecordSet.EOF

    strADsPath = objRecordSet.Fields("ADsPath").Value

    objOU.MoveHere strADsPath, vbNullString

    objRecordSet.MoveNext

Loop

Open in new window

0
 
LVL 15

Expert Comment

by:markpalinux
ID: 21821199


When I have that type of task I like to use dsmove - I just find it cleaner, I run csvde or dumps with vbscript before and after to check that all went well.

dsmove, dsquery, dsadd, etc all part of Windows 2003.


the script center at Microsoft website gives a very basic vbscript for move user:
http://www.microsoft.com/technet/scriptcenter/scripts/ad/users/manage/default.mspx
Set objOU = GetObject("LDAP://ou=sales,dc=na,dc=fabrikam,dc=com")

objOU.MoveHere _
    "LDAP://cn=BarrAdam,OU=hr,dc=na,dc=fabrikam,dc=com", vbNullString

Mark
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now