none
Move Users through a .txt

    Question

  • 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


    Tuesday, March 13, 2012 4:30 PM

Answers

  • 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


    Thursday, March 15, 2012 2:47 PM

All replies

  • 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


    Tuesday, March 13, 2012 4:50 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:08 PM
  • Hi,

    I've this script, following below:



    Option Explicit

    Dim strFileName, strTargetOU, strUserDN
    Dim objFSO, objInputFile, objOU, objUser

    Const ADS_PROPERTY_CLEAR=1
    Const ForReading = 1

    strFileName = "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 5:21 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.


    ¯\_(ツ)_/¯

    Tuesday, March 13, 2012 11:05 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


    Thursday, March 15, 2012 2:47 PM