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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript to retrieve userWorkstation attribute from AD.

Status
Not open for further replies.

wlfpackr

IS-IT--Management
May 3, 2003
161
0
0
US
So I've run into a rather confusing issue with a script I'm writing to update userWorkstations attribute. Below is a simplified version of what I'm doing (hopefully with no typos):

Code:
strUserDN = "CN=username,OU=Users,DC=xyz,DC=com"

Set objUser = GetObject("LDAP://" & strUserDN)
strUser = objUser.Get("samaccountname")
strComps = objUser.Get("userWorkstations")
 
 WScript.Echo "User: " & strUser & vbCrLf & "Workstations: " & strComps


It works fine if the userWorkstation attribute is populated, but if it's empty I get an error:

Code:
Error: The directory property cannot be found in the cache
Code:  8000500D
Source:  Active Directory

If I run the code with a valid user DN that has information in the userWorkstation attribute, script works fine. If I run the code with a valid user DN that does not have any information in the userWorkstation attribute, the error above is returned and refers to strComps = objUser.Get("userWorkstations").

I tried using an If/Then statement with <> "" or IsNull() but that doesn't work either. Any suggestions other than an On Error Resume Next? I'd like to understand what is actually going on.

=================
There are 10 kinds of people in this world, those that understand binary and those that do not.
 
So I took a shot in the dark and used the following code:

Code:
strUserDN = "CN=username,OU=Users,DC=xyz,DC=com"

Set objUser = GetObject("LDAP://" & strUserDN)
strUser = objUser.samaccountname
strComps = objUser.userWorkstations
 
 WScript.Echo "User: " & strUser & vbCrLf & "Workstations: " & strComps

[\code]

It works without any problem.  I would love to know why?



=================
There are 10 kinds of people in this world, those that understand binary and those that do not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top