+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Script for moving computers to a specific OU in active directory. in Coding and Web Development; I need some help with a script I found here: Q and A - TechNet VB Script to move computers ...
  1. #1

    Join Date
    Jan 2008
    Posts
    16
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Script for moving computers to a specific OU in active directory.

    I need some help with a script I found here:
    Q and A - TechNet VB Script to move computers to specific OU
    I want to be able to move a rooms computers to a specific OU for controlled assessments, then use a similar script to move them back again.
    The script I have works only if used on the same domain as the PC's in question, trouble is, the script will need to be run from a teacher PC (staff domain) and move PC's on the pupil domain.
    Is it possible to specify a domain to look for in the script? I am a complete novice at scripting!

  2. #2
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Permissions aside, could you not just fill in strSearchRoot so you define the domain you want?.

  3. #3

    Join Date
    Jan 2008
    Posts
    16
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi, thanks for the reply.
    I have specified the OU + domain by adding this line:
    strSearchRoot = "OU=Classroom Pc's,OU=Senior School,OU=Managed Computers,DC=stbenedicts,DC=org,DC=uk"
    But I get an error: A referral was returned from the server, I'm pretty sure I have delegated control correctly.
    If I run the script still from the DC on the pupil domain the script works.
    Am I missing something?

  4. #4
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    It should be:

    strSearchRoot = "DC=stbenedicts,DC=org,DC=uk"

  5. #5

    Join Date
    Jan 2008
    Posts
    16
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I am still getting the referral error, here is the script I am running:

    OPTION EXPLICIT
    Const ADS_PROPERTY_CLEAR = 1
    DIM strSearchFilter, strSearchRoot, objRootDSE
    DIM cn,cmd,rs, strSearchScope
    DIM objNewOU, strNewOU

    ' ************************************************** ******
    ' * Setup
    ' ************************************************** ******

    ' Specify the distinguished name of the new OU to move the computers to

    strNewOU = "OU=ICT1,OU=Assesment with Word,OU=Controlled assessments,DC=stbenedicts,DC=org,DC=uk"

    ' Modify the filter to query for your department.

    ' This filter will find all computers where the name starts with "2SDS"

    strSearchFilter = "(&(objectCategory=Computer)(sAMAccountName=2SDS*) )"
    strSearchRoot = "DC=stbenedicts,DC=org,DC=uk"
    strSearchScope = "subtree"
    set objNewOU = GetObject("LDAP://" & strNewOU)
    Set cn = CreateObject("ADODB.Connection")
    Set cmd = CreateObject("ADODB.Command")
    cn.open "Provider=ADsDSOObject;"

    Set cmd.ActiveConnection = cn

    cmd.CommandText = "<LDAP://" & strSearchRoot & ">;" & strSearchFilter & ";ADsPath;" & strSearchScope
    cmd.Properties("Page Size") = 1000

    Set rs = cmd.Execute

    ' loop through the search results

    while rs.eof<> true and rs.bof<>true
    objNewOU.MoveHere rs(0),vbNullString
    rs.movenext
    wend

    rs.close
    cn.close

    wscript.echo "Completed"

    private function getDomainRoot
    ' Bind to RootDSE - this object is used to
    ' get the default configuration naming context
    ' e.g. dc=wisesoft,dc=co,dc=uk

    set objRootDSE = getobject("LDAP://RootDSE")
    getDomainRoot = objRootDSE.Get("DefaultNamingContext")
    end function

  6. #6
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 4
    Last Post: 14th July 2010, 03:16 PM
  2. Replies: 29
    Last Post: 16th October 2008, 04:28 PM
  3. Replies: 6
    Last Post: 11th July 2007, 09:53 PM
  4. Replies: 4
    Last Post: 10th November 2006, 11:28 AM
  5. VBS script for prestaging computers anyone?
    By ChrisH in forum Scripts
    Replies: 7
    Last Post: 23rd June 2006, 09:59 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •