Move Computer Accounts from Computer Container

Discussion in 'Scripting' started by Jordi, Sep 27, 2008.

  1. Jordi

    Jordi Guest

    I am looking to automate the process of moving computers that get into our
    computers container. I've found scripts that talk about moving computers,
    but is it possible to scan the first 4-5 characters of the computer account
    name an move it based on that.


    Computer name starts with...

    PS-E... would get moved to a specific OU
    PS-S... would get moved to a different OU
    PS-T... would get moved to a different OU

    Here are the links to the information i've found so far...

    Much Appreciated,

    Jordi, Sep 27, 2008
    1. Advertisements

  2. In brief, the code to move the computers could be similar to below:
    Option Explicit
    Dim objPSE, objPSS, objPST
    Dim objContainer, objComputer, strOU

    ' Bind to the target OU's (do this once).
    Set objPSE = GetObject("LDAP://ou=PSE,ou=West,dc=MyDomain,dc=com")
    Set objPSS = GetObject("LDAP://ou=PSS,ou=West,dc=MyDomain,dc=com")
    Set objPST = GetObject("LDAP://ou=PST,ou=West,dc=MyDomain,dc=com")

    ' Bind to container object.
    Set objContainer = GetObject("LDAP://cn=Computers,dc=MyDomain,dc=com")
    ' Filter on computer objects.
    objContainer.Filter = Array("computer")

    ' Enumerate all computers in container.
    For Each objComputer In objContainer
    ' Check first 4 characters (upper case) of NetBIOS Name.
    strOU = Left(UCase(objComputer.sAMAccountName), 4)
    Select Case strOU
    Case "PS-E"
    objPSE.MoveHere objComputer.AdsPath, vbNullString
    Case "PS-S"
    objPSS.MoveHere objComputer.AdsPath, vbNullString
    Case "PS-T"
    objPST.MoveHere objComputer.AdsPath, vbNullString
    End Select
    Richard Mueller [MVP], Sep 27, 2008
    1. Advertisements

  3. Jordi

    Jordi Guest

    Brilliant!! This is exactly what i was looking. Thanks Richard!!
    Jordi, Sep 29, 2008
  4. Jordi


    Feb 9, 2012
    Likes Received:
    Error Message - no such object on the server

    This is a great script and could be very useful...IF I can get it to work...

    I've changed the lines for my environment but I'm gettting the following:

    (null): there is no such object on the server.

    Exit code: 0 , 0000h

    Any help would be greatly appreciated!!

    dwagner1, Feb 9, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.