' Auteur: Thierry DEMAN (BY THE WAY) ' -------------------------------------------------------------------------------------------------- ' Fonctionnement: ' -------------------------------------------------------------------------------------------------- '************************** VARIABLES SYSTEMES ************************** dim u,v,w,x '************************** VARIABLES ************************** ' ------------------------------------- DEBUT DE PROGRAMME ------------------------------------------- Set oRootDSE = GetObject("LDAP://RootDSE") strDomainNC = oRootDSE.Get("defaultNamingContext") Set oConnection = CreateObject("ADODB.Connection") oConnection.Provider = "ADsDSOObject" oConnection.Open "ADs Provider" Set oRecordset = oConnection.Execute(";(&(objectCategory=user)(objectCategory=contact));distinguishedName;subtree") If Not oRecordset.EOF Then While Not oRecordset.EOF if not(isnull(oRecordset.Fields("distinguishedName"))) Then DnName=oRecordset.Fields("distinguishedName") If Instr(ucase(Dnname),"OU=PASTOUCHER")=0 Then u=u+1 UpdateAccount(DnName) End if end if oRecordset.movenext Wend End If Wscript.echo "Enregs ="+Cstr(u) Wscript.echo "Enregs corrected="+Cstr(w) Wscript.echo "Bad Enregs="+Cstr(v) x=u-v wscript.echo "Good Enregs="+Cstr(x) wscript.quit ' --------------------------------- DECLARATION DES FONCTIONS ------------------------------------- ' ********* FIN DE PROGRAMME *********** Function UpdateAccount(DnName) Dim oUser wscript.echo dnname set oUser=GetObject("LDAP://"+DnName) samaccountname=ouser.samaccountname sn=oUser.sn givenname=oUser.givenname DisplayName=Trim(oUser.DisplayName) If len(sn)=0 OR len(Givenname)=0 Then If Len(DisplayName)=0 Then wscript.echo samaccountname&" | No Sn,Givenname or DisplayName" v=v+1 Else x=Instr(DisplayName, " ") IF x>0 Then GivenName=left(DisplayName,x-1) sn=Mid(Displayname,x+1) NewDisplayName=Ucase(sn)+" "+givenname wscript.echo "CORRRECTED| "&samaccountname&" | "&sn&" | "&givenname&" | "&DisplayName&" | "&NewDisplayName w=w+1 Else wscript.echo samaccountname&" | No Sn,Givenname or DisplayName" v=v+1 End IF End IF Else NewDisplayName=Ucase(sn)+" "+givenname wscript.echo samaccountname&" | "&sn&" | "&givenname&" | "&DisplayName&" | "&NewDisplayName oUser.put "DisplayName", NewDisplayName oUser.setinfo End if End Function