[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1280
  • Last Modified:

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

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
towo2002
Asked:
towo2002
1 Solution
 
RobSampsonCommented:
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
 
markpalinuxCommented:


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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now