Move Users through a .txt
-
Tuesday, March 13, 2012 4:30 PM
Hi There,
Is it possible a script that moves users through a .txt with the login of the person (sAMAccountName)?
Thankful.
Rafael S. AMARAL
U. P. Mackenzie- Edited by Rafael S. AMARAL Tuesday, March 13, 2012 4:51 PM
All Replies
-
Tuesday, March 13, 2012 4:41 PM
Please don't double post.
Yes - did you look in the repository for that script?
http://gallery.technet.microsoft.com/scriptcenter/site/search?query=move&f%5B2%5D.Value=move&f%5B2%5D.Type=SearchText&f%5B0%5D.Value=activedirectory&f%5B0%5D.Type=RootCategory&f%5B0%5D.Text=Active%20Directory&f%5B1%5D.Value=useraccounts&f%5B1%5D.Type=SubCategory&f%5B1%5D.Text=User%20Accounts&ac=8
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Tuesday, March 13, 2012 4:43 PM
-
Tuesday, March 13, 2012 4:50 PM
Hi jrv.
I saw, but I only found a script from OU to OU.
I would like from TXT (sAMAccountName) to OU.
Rafael S. AMARAL
U. P. Mackenzie- Edited by Rafael S. AMARAL Tuesday, March 13, 2012 4:51 PM
-
Tuesday, March 13, 2012 5:08 PM
Just modify any script that is close to tak ein put from a text file.
Do what you can and posst teh script with your specific 2question.
We do not write your script for you. If someone has a scriptthat is close they may post it.
Also look into
dsget and dsmove. They are available as utilities on an domain controller.and cantake input from a file using the batch command FOR.
¯\_(ツ)_/¯
-
Tuesday, March 13, 2012 5:21 PM
Hi,
I've this script, following below:
Option Explicit
Dim strFileName, strTargetOU, strUserDN
Dim objFSO, objInputFile, objOU, objUserConst ADS_PROPERTY_CLEAR=1
Const ForReading = 1strFileName = "C:\scripts\test.txt"
Set objFSO = CreateObject("scripting.filesystemobject")
Set objInputFile = objFSO.OpenTextFile(strFileName,ForReading)strTargetOU = "LDAP://ou=teste,dc=valdac,dc=com,dc=br"
Set objOU = GetObject(strTargetOU)
Do While Not objInputFile.AtEndOfStream
strUserDN = Trim(objInputFile.ReadLine)
Set objUser = GetObject(strUserDN)
objUser.SetInfo
objOU.MoveHere strUserDN,vbNullString
Loop
But this error appears.Rafael S. AMARAL U. P. Mackenzie
-
Tuesday, March 13, 2012 11:05 PM
The error is on line 20 . The script does not have 20 lines.
You say the file has samAccountName so the script will not work because it needs distinguishedName.
¯\_(ツ)_/¯
-
Thursday, March 15, 2012 2:47 PM
on error resume next
CONST ForReading = 1
Const ForAppending = 8
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oTS = oFS.OpenTextFile("Move.txt",ForReading)
set oLS = oFS.OpenTextFile("movecomputerlog.txt",ForAppending,True)
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
'Modify the following line to desired OU
Set objNewOU = GetObject("LDAP://OU=XXXXXXX,OU=XXXXX,dc=XXXXX,dc=com,dc=br")
Do Until oTS.AtEndOfStream
strComputer = oTS.ReadLine
strQuery = _
"<LDAP://" & strDNSDomain & ">;(&(ObjectClass=user)(ObjectCategory=person)(samAccountName=" & strComputer & "));adspath,cn;subtree"
objCommand.CommandText = strQuery
Set RS = objCommand.Execute
While not RS.EOF
strPath = RS.Fields("adspath")
strName = "CN=" & RS.Fields("cn")
oLS.Writeline(strPath)
Set objMoveComputer = objNewOU.MoveHere(strPath,strName)
RS.MoveNext
Wend
Loop
The file name is move.txt within the file must contain the logins.
Rafael S. AMARAL
U. P. Mackenzie- Edited by Rafael S. AMARAL Thursday, March 15, 2012 2:48 PM
- Marked As Answer by Rafael S. AMARAL Thursday, March 15, 2012 2:49 PM

