|
jbowen -> RE: Move a list of computer to an OU (1/10/2005 11:29:58 AM)
|
edit - 01/10/05 *** I figured it out. The txt file I was using did not have the CN correct. I was attempting to use the login name. Once I corrected that all is good. I changed this to allow me to move users. However something really wierd is happening. The script worked flawlessly two days ago. Now it doesn' t work at all. Any help? quote:
On error resume next ' Declare Variables Dim ObjUserPath Dim ObjUserCN Dim ObjUser ' Begin procedure to read from text file Const ForReading = 1 Set objDictionary = CreateObject(" Scripting.Dictionary" ) Set objFSO = CreateObject(" Scripting.FileSystemObject" ) ' Line to feed script a text list of Usernames to search Active Directory UserFile = InputBox(" Enter the path & file name of the text file with User names:" ) Set objTextFile = objFSO.OpenTextFile(UserFile, ForReading) i = 0 Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline objDictionary.Add i, strNextLine i = i + 1 Loop For Each objItem in objDictionary Set objConnection = CreateObject(" ADODB.Connection" ) objConnection.Open " Provider=ADsDSOObject;" ' Binds the connection to a command Set objCommand = CreateObject(" ADODB.Command" ) objCommand.ActiveConnection = objConnection ' LDAP filter to search Active Directory for each User from provided text file objCommand.CommandText = " <LDAP://dc=corp,dc=jhhs,dc=org>;(&(objectcategory=User)(cn=" & objDictionary.Item(objItem) & " ));ADsPath;subtree" ' objCommand.CommandText = " <LDAP://PDC_EMULATOR/dc=DOMAINNAME,dc=COM>;(&(objectcategory=computer)(cn=" & objDictionary.Item(objItem) & " ));ADsPath;subtree" Set objRecordSet = objCommand.Execute While Not objRecordset.EOF ' If User found, distinguished path and CN name to another script strADsPath = objRecordset.Fields(" ADsPath" ) Set ObjUser = GetObject(strADsPath) ObjUserPath = ObjUser.DistinguishedName ObjUserCN = ObjUser.CN objRecordset.MoveNext Wend objConnection.Close ' Operations to move to new OU Set objNewOU = GetObject(" LDAP://10001 - Nursing Administration,DC=corp,DC=jhhs,DC=org" ) Set objMoveUser = objNewOU.MoveHere (" LDAP://" & ObjUserPath, " CN=" & ObjUserCN) ' Set objNewOU = GetObject(" LDAP://PDC_EMULATOR/OU=TARGET_OU,DC=DOMAINNAME,DC=COM" ) ' Set objMoveComputer = objNewOU.MoveHere (" LDAP://PDC_EMULATOR/" & ObjCompPath, " CN=" & ObjCompCN) Next [&:][&:][8D]
|
|
|
|