Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classic asp - Only some active directory attributes can be updated.

Status
Not open for further replies.

Tord Bergset

Systems Engineer
Dec 8, 2017
3
0
0
NO
Hi

I have a classic asp script that is used to update some active directory user object attributes; email address, phone number and company name
The problem is that I am not able to write to these attributes using my script. Reading attributes works like a charme, but not able to write updates to attributes.
I have testet many things and found that certain attributes wirk as expected, but not the 3 I need.
Can anyone see what I am doing wrong??

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Const ADS_SECURE_AUTHENTICATION=&h0001
Const ADS_SERVER_BIND=&h0200
Const ADS_PROPERTY_UPDATE = 2

'Connect to Active directory...using user's credentials
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
With objConnection
.Properties("User ID") = strInput_UserID
.Properties("Password") = strInput_UserPWD
.Properties("Encrypt password") = True
End With
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = 2
objCommand.CommandText ="select sn,name,distinguishedName,sAMAccountName FROM '"& strDomain &"' where sAMAccountname='"& strUserToEdit &"' ORDER by sAMAccountname"
Set objRecordSet = objCommand.Execute

'Reading data from AD
userdn = objRecordSet.fields("distinguishedname")
userFullname = objRecordSet.fields("name") & " " & objRecordSet.fields("sn")
arrPath = Split(userdn, ",",2)
strOUdn = arrPath(1)
strUserOU = "LDAP://mydomain.no/" & strOUdn

'Time to write som information to AD ----- the problem section -------

Set objIADS = GetObject("WinNT:").OpenDSObject("WinNT://mydomain.no/", strAdminUser, strAdminPWD, ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
Set objIADSUser = objIADS.GetObject("user", strInput_UserID)

If Err.Number = 0 Then
On Error Resume next
With objIADSUser
'-------------------------------------------------------------------------------------------
'------------------- These 5 work just fine -----------
'-------------------------------------------------------------------------------------------
.SetPassword strRndPassword
.AccountDisabled = False
.IsAccountLocked = False
.Put "PasswordExpired", CLng(1)
.put "description", "My description"

'-------------------------------------------------------------------------------------------
'------------------- The following 3 attributes I am not able to update/write to -----------
'-------------------------------------------------------------------------------------------
' .put "mail" = "test@email.com"
' .put "telephoneNumber", "7775555333"
' .put "company", "MyCompanyName"

.SetInfo
End With
End If[/color][/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top