jeudi 17 décembre 2009

VBS - Update Attribute Active Directory - Objet user company

Sujet : VBS - Update Attribute Active Directory

Exemple sur un changement de l'attribut user company :

set objConnection = CreateObject("ADODB.Connection")
set objCommand = CreateObject("ADODB.Command")
Const ADS_SCOPE_SUBTREE = 2
objConnection.Provider = "ADsDSOObject"
objConnection.Open("Active Directory Provider")
objCOmmand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "Select Name,company, ADsPath FROM 'LDAP://DC=test,DC=lan' WHERE objectCategory='user' "
set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst()
Do Until objRecordSet.EOF
Tableau=Split(objRecordSet.Fields("ADsPath").Value,",")
TrouveOU = Mid(Tableau(1),InStr(Tableau(1),"=")+1)
if TrouveOU = "Users" or TrouveOU = "Comptes de Services" or TrouveOU = "Comptes Techniques" or TrouveOU = "Services" then
else
strUser = objRecordSet.Fields("ADsPath").Value
strNewCompany = "TEST"
Set objUser = GetObject(strUser)
objUser.company = strNewCompany
objUser.SetInfo
end if
objRecordSet.MoveNext()
Loop
wscript.echo "mise à jour effectuée"

Mots : vbs , update , attribute , active directory , objet , user , company , changement , ou , ldap