|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drop-down list on Active Directory
Option Explicit Dim adoCommand, adoConnection, strBase, strFilter, strAttributes Dim strQuery, adoRecordset, strDN, objUser ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire Active Directory domain. strBase = "<LDAP://dc=MyDomain,dc=com>" ' Filter on user objects. strFilter = "(&(objectCategory=person)(objectClass=user))" ' Comma delimited list of attribute values to retrieve. strAttributes = "distinguishedName" ' Construct the LDAP syntax query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False ' Run the query. Set adoRecordset = adoCommand.Execute ' Enumerate the resulting recordset. Do Until adoRecordset.EOF ' Retrieve values. strDN = adoRecordset.Fields("distinguishedName").Value ' Bind to user object. Set objUser = GetObject("LDAP://" & strDN) ' Modify attribute values. objUser.Put "streetAddress", "Building 43" & _ VbCrLf & "One Microsoft way" objUser.Put "l", "Redmond" objUser.Put "st", "Washington" objUser.Put "postalCode", "98503" objUser.Put "c", "US" objUser.Put "postOfficeBox", "2222" ' Save changes. objUser.SetInfo adoRecordset.MoveNext Loop ' Clean up. adoRecordset.Close adoConnection.Close The script is working but when you have to assign the country it shows the space for the country in blank because on the Active Directory you have a drop-down list where you choose the country, so the sentence ObjUser.Put "c", "US" It is not working, neither if you write "United States". Does anyone know how to do it to work? There are actually 3 attributes for country, c, co, and countryCode. To
assign "US" I use the following: objUser.Put "c", "US" objUser.Put "co", "UNITED STATES" objUser.Put "countryCode", 840 I would have to look up the reference I used to get this information, but the code numbers and abbreviations are international standards. Show quote "Paloma" <Pal***@discussions.microsoft.com> wrote in message news:B7E2D806-CFB4-4D77-9281-BEFE3303197C@microsoft.com... >I used this script to give all users the same postal address. > > Option Explicit > > Dim adoCommand, adoConnection, strBase, strFilter, strAttributes > > Dim strQuery, adoRecordset, strDN, objUser > > > ' Setup ADO objects. > > Set adoCommand = CreateObject("ADODB.Command") > Set adoConnection = CreateObject("ADODB.Connection") > adoConnection.Provider = "ADsDSOObject" > adoConnection.Open "Active Directory Provider" > adoCommand.ActiveConnection = adoConnection > > > > ' Search entire Active Directory domain. > strBase = "<LDAP://dc=MyDomain,dc=com>" > > > ' Filter on user objects. > strFilter = "(&(objectCategory=person)(objectClass=user))" > > > > ' Comma delimited list of attribute values to retrieve. > strAttributes = "distinguishedName" > > > > ' Construct the LDAP syntax query. > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" > adoCommand.CommandText = strQuery > adoCommand.Properties("Page Size") = 100 > adoCommand.Properties("Timeout") = 30 > adoCommand.Properties("Cache Results") = False > > > > ' Run the query. > Set adoRecordset = adoCommand.Execute > > > ' Enumerate the resulting recordset. > Do Until adoRecordset.EOF > > ' Retrieve values. > strDN = adoRecordset.Fields("distinguishedName").Value > > ' Bind to user object. > > Set objUser = GetObject("LDAP://" & strDN) > > ' Modify attribute values. > > objUser.Put "streetAddress", "Building 43" & _ > VbCrLf & "One Microsoft way" > objUser.Put "l", "Redmond" > objUser.Put "st", "Washington" > objUser.Put "postalCode", "98503" > objUser.Put "c", "US" > objUser.Put "postOfficeBox", "2222" > > ' Save changes. > objUser.SetInfo > > > adoRecordset.MoveNext > Loop > > > > ' Clean up. > > adoRecordset.Close > > adoConnection.Close > > > > > The script is working but when you have to assign the country it shows > the > space for the country in blank because on the Active Directory you have a > drop-down list where you choose the country, so the sentence > > ObjUser.Put "c", "US" > > It is not working, neither if you write "United States". > Does anyone know how to do it to work? |
|||||||||||||||||||||||