Written
October 24, 2011
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_INITTYPE_GC = 3
CONST ADS_NAME_TYPE_NT4 = 3
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)
END FUNCTION