Renaming AD accounts

Author Message
nazirin

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 5/9/2005
  • Location:
  • Status: offline
Renaming AD accounts Monday, May 09, 2005 11:57 PM (permalink)
0
I am very new to VB scriting, can someone help me with renamin AD account code. I have found this script on the internet but it comes up with error "The object does not exist".


' ------ SCRIPT CONFIGURATION ------
strParentDN = "<ParentDN>" ' e.g. cn=Users,dc=rallencorp,dc=com
strUserOldName = "<OldUserName>" ' e.g. jsmith
strUserNewName = "<NewUserName>" ' e.g. jim
' ------ END CONFIGURATION ---------

set objCont = GetObject("LDAP://" & strParentDN)
objCont.MoveHere "LDAP://cn=" & strUserOldName & "," & strParentDN, _
"cn=" & strUserNewName
set objUser = GetObject("LDAP://cn=" & strUserNewName & "," & strParentDN)
objUser.Put "sAMAccountName", strUserNewName
objUser.SetInfo
WScript.Echo "Rename successful"
 
#1
    nazirin

    • Total Posts : 2
    • Scores: 0
    • Reward points : 0
    • Joined: 5/9/2005
    • Location:
    • Status: offline
    Re: Renaming AD accounts Tuesday, May 10, 2005 3:38 AM (permalink)
    0
    No one has answered to my problem yet, please I want help in renaming user accounts in AD.
     
    #2
      Country73

      • Total Posts : 754
      • Scores: 10
      • Reward points : 0
      • Status: offline
      Re: Renaming AD accounts Tuesday, May 10, 2005 4:28 AM (permalink)
      0
      Where is the error pointing to?

      Is this an EXACT part of the script you are using??

      strParentDN = "<ParentDN>" ' e.g. cn=Users,dc=rallencorp,dc=com
      strUserOldName = "<OldUserName>" ' e.g. jsmith
      strUserNewName = "<NewUserName>" ' e.g. jim

      If so, you need to insert the correct information for "<ParentDN>", "<OldUserName>", "<NewUserName>"
       
      #3
        token

        • Total Posts : 1917
        • Scores: 0
        • Reward points : 0
        • Joined: 1/14/2005
        • Location:
        • Status: offline
        Re: Renaming AD accounts Tuesday, May 10, 2005 4:51 AM (permalink)
        0
        If is not the EXACT code you are using, please post the exact code (preferrably) and the exact error message and at what line.

         
        #4
          netmarcos

          • Total Posts : 55
          • Scores: 0
          • Reward points : 0
          • Joined: 12/7/2004
          • Location: USA
          • Status: offline
          Re: Renaming AD accounts Monday, May 16, 2005 8:53 AM (permalink)
          0
          The following script was designed to perform a post-migration cleanup of user account names. In the migration, each of the new user object names were set to the logon ID, but we wanted them to be named the user's full name. So the script pulls each user account from a specific AD OU and checks to see if the object name matches the displayname. If not it renames the account, if yes, it leaves it alone. If the displayname is blank, that is simply logged. Maybe it will help you out a bit.


          Const ADS_SCOPE_SUBTREE = 2
          Const ForAppending = 8
          
          
          Dim oWshShell		'Windows shell script
          Dim objFSO		'Scripting File System
          Dim objFile		'Open text file
          Dim objConnection	'ADO conection
          Dim objCommand		'ADO command
          Dim objRecordSet	'Object to hold attributes from AD Subnet properties
          Dim objUser		'AD User Account
          Dim strUser		'AD User Account distinguished name
          Dim strDN		'AD User account Display name attribute
          Dim strON		'AD User account Name attribute
          Dim sPath
          Dim strNewPath
          Dim newobj
          Dim Cont
          
          Set oWshShell = CreateObject("WScript.Shell")
          Set objConnection = CreateObject("ADODB.Connection")
          Set objCommand =   CreateObject("ADODB.Command")
          objConnection.Provider = "ADsDSOObject"
          objConnection.Open "Active Directory Provider"
          Set objCommand.ActiveConnection = objConnection
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objFile = objFSO.OpenTextFile _
          ("C:\Accounts.log",ForAppending,True)
          sOU = UCase(Inputbox("Enter the name of the local OU of the accounts to be modified.", "MyCompany"))
          objFile.WriteBlankLines(1)
          objFile.WriteLine "=========================================================="
          objFile.WriteLine "Log opened at " & Now
          objFile.WriteBlankLines(1)
          sPath = "OU=" & sOU & ",OU=Users,OU=Accounts,OU=US,DC=mycompany,DC=net"
          objFile.WriteLine "Processing " & sPath
          objFile.WriteBlankLines(1)
          
          objCommand.CommandText = _
          "Select Name, DisplayName, distinguishedName from 'LDAP://" & sPath & "'" _
          & " where objectClass='user'"
          objCommand.Properties("Page Size") = 1000
          objCommand.Properties("Timeout") = 30
          objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
          objCommand.Properties("Cache Results") = False
          Set objRecordSet = objCommand.Execute
          
          If objRecordSet.EOF = False Then
          objRecordSet.MoveFirst
          
          Do While objRecordSet.EOF = False
          strDN = objRecordSet.Fields("DisplayName").Value
          strON = objRecordSet.Fields("Name").Value
          strUser = objRecordSet.Fields("distinguishedName").Value
          
          If strDN = strON then
          
          objFile.WriteLine "Current and target name are the same for " & strON
          ObjFile.WriteBlankLines (1)
          Else
          
          If strDN <> "" Then
          objFile.WriteLine "New Name for " & strON & " will be " & strDN
          
          strNewPath = "CN="& strDN
          
          
          Set cont = GetObject("LDAP://" & sPath)
          
          Set newobj = cont.MoveHere("LDAP://" & strUser, strNewPath)
          
          
          If Err.Number <> 0 Then WScript.Echo Err.Number & Err.Description
          Set objUser = nothing
          Set cont	= nothing
          Set newobj 	= nothing
          ObjFile.WriteBlankLines (1)
          Else
          objFile.WriteLine  "Display name value has not been set for " & strON & ". Name cannot be changed."
          ObjFile.WriteBlankLines (1)
          End If
          
          End If
          objRecordSet.MoveNext
          Loop
          Else
          
          End If
          objFile.WriteLine "=========================================================="
          objFile.WriteLine "End of user processing."
          objFile.WriteLine "=========================================================="
          objFile.WriteLine "Log file closed at " & Now
          objFile.WriteBlankLines(2)
          objFile.Close
          wscript.echo "Done."
          oWshShell.run "notepad.exe C:\Accounts.log", 7, True
          
          
          '***************************************************************************************
          
          
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9