Board index » Visual Studio » ADSI User object issue

ADSI User object issue

Visual Studio263
I have a couple of questions around the vbscript GetObject command and

the resultant User object from Active Directory.



I want to be able to get and set some fields but all I get is an error

message



The fields I cannot get from Active Directory are:



pager, mobile, fax, title, department.



When I try to get these (along with other fields that DO come through)

the page fails with



"The Active Directory property cannot be found in the cache"



This is not a security issue, as I log in as the domain administrator

and it still fails to find these values.



here is my code. Can someone help me out here?





Set User = GetObject("LDAP://CN=" & userID &

",OU=eCentric,DC=amr,DC=int") WriteLn("CN: " & User.Get("cn"))

WriteLn("sAMAccountName: " & User.Get("sAMAccountName"))

WriteLn("DisplayName: " & User.Get("DisplayName"))



WriteLn("TelephoneNumber: " & User.Get("TelephoneNumber"))

WriteLn("TelephonePager: " & User.Get("OtherPager"))



WriteLn("TelephoneMobile: " & User.Get("mobile"))

WriteLn("FaxNumber: " & User.Get("otherFacsimileTelephoneNumber"))

WriteLn("Title: " & User.Get("Title"))

WriteLn("Department: " & User.Get("Department"))


-
 

Re:ADSI User object issue

Chris Smith wrote:



Quote
I have a couple of questions around the vbscript GetObject command and

the resultant User object from Active Directory.



I want to be able to get and set some fields but all I get is an error

message



The fields I cannot get from Active Directory are:



pager, mobile, fax, title, department.



When I try to get these (along with other fields that DO come through)

the page fails with



"The Active Directory property cannot be found in the cache"



This is not a security issue, as I log in as the domain administrator

and it still fails to find these values.



here is my code. Can someone help me out here?





Set User = GetObject("LDAP://CN=" & userID &

",OU=eCentric,DC=amr,DC=int") WriteLn("CN: " & User.Get("cn"))

WriteLn("sAMAccountName: " & User.Get("sAMAccountName"))

WriteLn("DisplayName: " & User.Get("DisplayName"))



WriteLn("TelephoneNumber: " & User.Get("TelephoneNumber"))

WriteLn("TelephonePager: " & User.Get("OtherPager"))



WriteLn("TelephoneMobile: " & User.Get("mobile"))

WriteLn("FaxNumber: " & User.Get("otherFacsimileTelephoneNumber"))

WriteLn("Title: " & User.Get("Title"))

WriteLn("Department: " & User.Get("Department"))



Hi,



A few points. The "Get" method raises an error if the attribute does not

have a value. You should either trap the error, or address the property

directly. For example:



WriteLn("TelephoneMobile: " & User.mobile)



With this syntax, "User.mobile" will be a blank string if the "mobile"

attribute has no value, and no error is raised. Otherwise, you could trap

the error with code similar to:



On Error Resume Next

WriteLn("TelephoneMobile" & User.Get("mobile"))

If Err.Number <>0 Then

On Error GoTo 0

WriteLn("TelephoneMobile has no value")

End If

On Error GoTo 0



Next, the "Other" attributes are multivalued and should be enumerated.

Treating them as strings will raise an error. For example, you could use:



arrstrOtherPager = User.otherPager

For Each strPager In arrstrOtherPager

WriteLn("Pager: " & strPager)

Next



Another syntax I have seen uses the GetEx method as follows:



For Each strPager In User.GetEx("otherPager")

WriteLn("Pager: " & strPager)

Next



Just as a guess, perhaps your snippet raised an error when you attempted to

access the "otherPager" attribute as a string (instead of as a collection or

array) and the error stopped the script. This could explain why all the

following lines did not display values.



I hope this helps.



--

Richard

Microsoft MVP Scripting and ADSI

HilltopLab web site - www.rlmueller.net">www.rlmueller.net

--





-