?
Solved

VB Script to move computers in AD

Posted on 2005-03-25
6
Medium Priority
?
2,092 Views
Last Modified: 2012-08-13
I need a script that will move a computer from the "Computers" container in Active directory to an OU called "Test" inside of an OU called "Workstations"

Here's a diagram of how it looks
My.Domain.net
   Computers
         MyComputer
   Workstations
         Test
             (This is where I'd like MyComputer to move to)

I hope that made sense.  This is the script I'm currently using and running into errors with.

dim objOU, intReturn, objRootDSE, strDNSDomain
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
Set objOU = GetObject("LDAP://OU=Workstations,OU=Test," & strDNSDomain)
intReturn = objOU.MoveHere _
    ("LDAP://CN=MyComputer,CN=Computers," & strDNSDomain, vbNullString)

I'm currently getting this Windows Script Host Error Message
Script: C:/blah/blah/blah/move.vbs
Line: 5
Char: 1
Error: There is no such object on the server.
Code: 8072030
Source: (null)



0
Comment
Question by:whiting002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 1000 total points
ID: 13637563
According to that error and what code you have shown me :

It is having an error with thie :

intReturn = objOU.MoveHere _
    ("LDAP://CN=MyComputer,CN=Computers," & strDNSDomain, vbNullString)

So does that mean MoveHere does not exist and you would need to find the actual command to move it ? Maybe try :

intReturn = objOU.Move _
    ("LDAP://CN=MyComputer,CN=Computers," & strDNSDomain, vbNullString)

Here are some sites :

http://www.computerperformance.co.uk/ezine/ezine27.htm

http://www.codecomments.com/archive300-2004-4-183910.html

Does any of that help you out :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13637862
I looked at those sites the your command in terms of the MoveHere part was correct, those sites will be able to help you out more though :)
0
 
LVL 22

Expert Comment

by:JesterToo
ID: 13640764
I don't believe you can move the contents of the CN this way... you need to iterate through the collection of computers and move each one individually.  You also need to name the OU's in "inside out" order... grandchildren, children, parent.  Here is a script that works for me in my W2K domain.

dim objOU, intReturn, objRootDSE, strDNSDomain

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

Set oTo   = GetObject("LDAP://OU=Test,OU=Workstations," & strDNSDomain)
Set oFrom = GetObject("LDAP://CN=MyComputer,CN=Computers," & strDNSDomain)
oFrom.Filter = Array("computer")

For Each oComputer In oFrom
   oTo.MoveHere oComputer.AdsPath, vbNullString
Next  

HTH,
Lynn
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 22

Assisted Solution

by:JesterToo
JesterToo earned 1000 total points
ID: 13640807
oooh,,, I just reread your question... I'd originally thought you were moving all the computers in the container"MyComputer"... since you're just moving a specific computer (named MyComputer), you only need to change 1 line of your script... Here is the correct line:

    Set objOU = GetObject("LDAP://OU=Test,OU=Workstations," & strDNSDomain)

Just reverse the order of the OU's so the child is named before its parent.  Also, the MoveHere method does not have a return value so you don't need the part "intReturn =" nor the parentheses around the method's parameters.

-- Lynn

0
 
LVL 2

Author Comment

by:whiting002
ID: 14183701
Hey sorry guys I just saw that this was still open.  I got this working a WHILE ago and I beleive I used both of your comments for help so I'm dividing the points.  Sorry I took so long.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 14183836
Thanks whiting for the grade and points :) I hope you got it sorted out :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

752 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