Solved

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

Posted on 2008-06-18
2
1,159 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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