Move a Computer Account

Moves a computer account from the Computers container in Active Directory to the Finance OU in the same domain.

3.8 Star
Add to favorites
Active Directory
E-mail Twitter Digg Facebook
  • I want to Pass a list of computer to this script from txt file. can you help me to get this done
    1 Posts | Last post September 02, 2012
    • I am using the code and it worked for one PC. But want to pass a list of pc from text file. how it can be done. can you help me please
  • If I wanted to use an Input box to state where I wanted to move the computer account too, how would I do this?
    3 Posts | Last post October 24, 2011
    • I get get this script to work but I will be updating groups of machines in AD which change location of OU and I dont want to ammend the script each time, I just want to put the ou location in a inputbox.
      I am new at this!!! Any help :-)
    • I haven't tested this out, but I believe it should work.  It's cobbled together from bits and pieces of other peoples code.  Best of luck!
      ' Constants required for name translate
      CONST ADS_NAME_TYPE_1779 = 1
      'get computer name
      Set wshNetwork = WScript.CreateObject("WScript.Network")
      strComputer = wshNetwork.ComputerName
      'get destination OU
      strOU = InputBox("Please enter the name of the destination OU in AD:")
      'move computer to the correct ou based on the input from the InputBox
      strContainer = "LDAP:// OU=" & strOU & ", DC=fabrikam, DC=com"
      SET objSystemInfo = CREATEOBJECT("ADSystemInfo")
      strDomain = objSystemInfo.DomainShortName
      Set objContainer = GETOBJECT(strContainer)
      strComputerDN = getComputerDN(strComputer,strDomain)
      objContainer.MoveHere "LDAP://" & strComputerDN, vbNullString
      FUNCTION getComputerDN(BYVAL strComputer,BYVAL strDomain)
      	' Function to get the distinguished name of a computer
      	' from the NETBIOS name of the computer (strcomputer)
      	' and the NETBIOS name of the domain (strDomain) using
      	' name translate
      	SET objTrans = CREATEOBJECT("NameTranslate")
      	' Initialize name translate using global catalog
      	objTrans.Init ADS_NAME_INITTYPE_GC, ""
      	' Input computer name (NT Format)
      	objTrans.SET ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"
      	' Get Distinguished Name.
      	getComputerDN = objTrans.GET(ADS_NAME_TYPE_1779)