wesleyw Posted February 26, 2009 Posted February 26, 2009 Does anyone know of a way of changing the firstname and surname fields of users in active directory via CLI? Wes
jamesb Posted February 26, 2009 Posted February 26, 2009 Using VBScript would do it. Welcome to the Script Center is a good place to start. 1
wesleyw Posted February 26, 2009 Author Posted February 26, 2009 Okay then I've got this VBS script: Const ADS_PROPERTY_UPDATE = 2 Set objUser = GetObject _ ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com") objUser.Put "givenName", "Ken" objUser.Put "initials", "E." objUser.Put "sn", "Myer" objUser.Put "displayName", "Myer, Ken" objUser.Put "physicalDeliveryOfficeName", "Room 4358" objUser.Put "telephoneNumber", "(425) 555-1211" objUser.Put "mail", "[email protected]" objUser.Put "wWWHomePage", "http://www.fabrikam.com" objUser.PutEx ADS_PROPERTY_UPDATE, _ "description", Array("Management staff") objUser.PutEx ADS_PROPERTY_UPDATE, _ "otherTelephone", Array("(800) 555-1212", "(425) 555-1213") objUser.PutEx ADS_PROPERTY_UPDATE, _ "url", Array("http://www.fabrikam.com/management") objUser.SetInfo Now how could I modifiy this to input all of my students from active directory and parse the username to create the First Name and Surname I.E. 08Bloggs-F GivenName = F Surname = Bloggs? Wes
jamesb Posted February 26, 2009 Posted February 26, 2009 I'm assuming that you want to do this from a CSV file? If so this script may help you.
Stuart_C Posted February 26, 2009 Posted February 26, 2009 built in Windows 2003 server command, dsmod! Plus some hevpfullness via excel to create the script itself. 1
srochford Posted February 26, 2009 Posted February 26, 2009 Script below should work - comment out the "oUser.setinfo" bit the first time you run it and it will just create a log showing what it's going to do. If that looks OK then re-rerun with with the setinfo line included. Don't have an AD handy to try this on but it's based on various scripts I've used which do "something" to every user so I'm reasonably confident :-) Set oRootDSE = GetObject("LDAP://RootDSE") sDomain = oRootDSE.Get("defaultNamingContext") Set oFSO=wscript.createobject("scripting.filesystemobject") sLogPath = "c:\temp\change" & right(year(date),2) & right("00" & month(date),2) & right("00" & day(date),2) & ".log" Set sLogFile = oFSO.opentextfile(sLogPath, 2, True) '2 is writing sLogFile.Close WriteLog "Started" Set oConn = CreateObject("ADODB.Connection") oConn.Provider = "ADsDSOObject" oConn.Open Set oCommand = CreateObject("ADODB.Command") oCommand.ActiveConnection = oConn oCommand.properties("Page Size")=100 ocommand.CommandText = ";(objectCategory=person);sAMAccountName;subTree" Set oRS = oCommand.Execute iCount=1 Do While Not oRS.EOF sUsername=trim(oRS("sAMAccountName")) sDN=oRS("distinguishedname") set oUser=getobject("LDAP://" & sDN) wscript.echo sUsername iDashPos=instr(sUsername,"-") if iDashPos<>0 then sSurname=mid(sUsername,3,iDashPos-1) sGivenName=mid(sUsername,iDashPos+1) oUser.sn=sSurname oUser.givenname=sGivenName writelog "Updating " & sUsername to " & sGivenName & " " & sSurname oUser.setinfo else writelog "Can't find a dash in " & sUsername end if oRS.MoveNext Loop writelog "Ended" Sub WriteLog(sToWrite) Set sLogFile = oFSO.opentextfile(sLogPath, 8) '8 is append sLogFile.write Date & " " & Time & ": " & sToWrite & vbCrLf sLogFile.Close End Sub
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now