kage13
Fri May 18 07:59:00 CDT 2007
Richard,
When running the code provided I'm getting an 80040E14 error at the
following line:
Set adoRecordset = adoCommand.Execute
In researching the error, I've found that it may represent a syntax error
but cannot find anything that jumps out.
Ideas?
TIA.
"Richard Mueller [MVP]" wrote:
> kage13 wrote:
>
> > Does anyone know of a way to change the phone format in AD for user
> > accounts?
> >
> > I'm a greenhorn on scripting and can use the help!!
> >
> > Currently, most of our users have the following phone format: ###/###-####
> >
> > We'd like to change that to: (###) ###-####. Is this possible at all? If
> > so, how would I go about scripting this?
>
> A VBScript program to modify the format of telephoneNumber attribute for all
> users in the domain follows. This uses ADO to retrieve the distinguishedName
> and telephoneNumber of all users with any value assigned to the
> telephoneNumber attribute. ADO cannot modify objects in AD, so the
> distinguishedName is used to bind to each user object. The phone number is
> modified and the changes saved. I assume the exact formats you gave, so I
> used the following to modify the phone number:
>
> strPhone = "(" & Replace(strPhone, "/", ") ")
>
> Others may suggest other methods. This simply appends "(" to the beginning
> and replaces every instance of "/" with ") ". If the format is not as
> expected, the result might be strange.
> ============
> Option Explicit
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
> Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN
> Dim strPhone, 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.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
> strBase = "<LDAP://" & strDNSDomain & ">"
>
> ' Filter on user objects that have a value assigned
> ' to the telephoneNumber attribute.
> strFilter = "(&(objectCategory=person)(objectClass=user)" _
> & "(telephoneNumber=*)"
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "distinguishedName,telephoneNumber"
>
> ' 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
> strPhone = adoRecordset.Fields("telephoneNumber").Value
> ' Modify format of phone number.
> strPhone = "(" & Replace(strPhone, "/", ") ")
> ' Bind to user object.
> Set objUser = GetObject("LDAP://" & strDN)
> ' Assign new phone number.
> objUser.telephoneNumber = strPhone
> ' Save changes.
> objUser.SetInfo
> ' Move to the next record in the recordset.
> adoRecordset.MoveNext
> Loop
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
> --
>
>
>