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.

    Example:

    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...

    http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/cptrvb11.mspx?pf=true

    http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/default.mspx?pf=true

    http://www.microsoft.com/communitie...6-ba1a8875c1a7&lang=en&cr=&sloc=en-us&m=1&p=1

    http://www.microsoft.com/communitie...6-ba1a8875c1a7&lang=en&cr=&sloc=en-us&m=1&p=1

    Much Appreciated,

    Jordi
     
    Jordi, Sep 27, 2008
    #1
    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
    Next
     
    Richard Mueller [MVP], Sep 27, 2008
    #2
    1. Advertisements

  3. Jordi

    Jordi Guest

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

    dwagner1

    Joined:
    Feb 9, 2012
    Messages:
    1
    Likes Received:
    0
    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!!

    Thanks!
     
    dwagner1, Feb 9, 2012
    #4
    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.