'_________________________________________________________________________________[ header ]__ ' Cerro Scripts: ADSDisplayName.vbs ' ' Copyright (c) 2005 Philipp Föckeler (www.cerrotorre.de) ' ' Sets the ADS common name and display name for users and contacts to ' "Surname, Givenname". This is done for a given ADS container and recursiv ' in all containers below. ' ' Usage: cscript ADSDisplayName.vbs ' BaseDN: Distinguished Name of an OU or Domain, ' where the names should be changed. ' Wscript.Echo "ads-displayname (c) 2004 Philipp Foeckeler (www.cerrotorre.de)" & vbCrLf '______________________________________________________________[ vars, consts, preparation ]__ CommandLine() ' BaseDN provided ? strBase = ";" ' we search for users and contacts ' with surname and givenname strFilter = "(&(|(objectclass=user)(objectclass=Contact))(&(sn=*)(givenName=*)));" strAttrs = "ADSPath;" strScope = "Subtree" ' ADO search Set con = CreateObject("ADODB.Connection") con.Provider = "ADsDSOObject" con.Open Set list = Con.Execute(strBase & strFilter & strAttrs & strScope) '___________________________________________________________________________________[ main ]__ Wscript.Echo "Setting name attributes for following objects:" & vbCrLf While Not list.Eof Set obj = GetObject(list.Fields(0).Value) strLast = obj.sn strFirst = obj.givenName strFullname = strLast & ", " & strFirst strObjDN = obj.distinguishedName strContainer = right(strObjDN, len(strObjDN) - len(obj.name) - 1) strNewObjDN = Replace("cn=" & strFullName, ",", "\,") Wscript.Echo "-- " & strFullname & " (" & strObjDN & ")" ' set display name obj.put "displayName" , strFullName obj.Setinfo ' rename object Set container = GetObject("LDAP://" & strContainer) container.MoveHere "LDAP://" & strObjDN, strNewObjDN Wscript.Echo "-- " & strFullname & " (" & strObjDN & ")" list.MoveNext wend '_______________________________________________________________________[ sub command line ]__ sub CommandLine() if (WScript.Arguments.Count=0) then wscript.echo "Sets the ADS common name and display name for users and contacts to" wscript.echo ". This is done for a given ADS container and" wscript.echo "recursiv in all containers below." & vbCrLf wscript.echo " cscript ads-displayname " & vbCrLf wscript.echo " BaseDN: Distinguished Name of an OU or domain," wscript.echo " where the names should be changed." wscript.quit end if end sub