• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2110
  • Last Modified:

Getting/Filtering on departmentNumber in AD query in vbscript

The following code appears to work for theAD attributes I am requesting, except for departmentNumber:

Response.Write objRS("name")

My query is:

Set objDomain = GetObject ("GC://RootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.provider ="ADsDSOObject"
objConn.Properties("User ID") = "xxxxxx" 'domain account with read access to LDAP
objConn.Properties("Password") = "xxxxxx" 'domain account password
objConn.Properties("Encrypt Password") = True
objConn.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objConn
objCom.CommandText ="select name,telephonenumber,mobile,mail,company,title,department,sAMAccountName,sn,userAccountControl,msexchhidefromaddresslists,departmentNumber FROM 'GC://"+objADsPath+"' where sAMAccountName='xxxxxx' and objectCategory='Person' AND objectClass = 'USER' ORDER by sAMAccountname"

I get the error "Item cannot be found in the collection corresponding to the requested name or ordinal." when I add departmentName to the output. Any help is greatly appreciated.
0
MegGrace
Asked:
MegGrace
  • 4
  • 3
1 Solution
 
pony10usCommented:
Try using just "department" (without the quotes)
0
 
MegGraceAuthor Commented:
Gah, just realized in the last paragraph I put departmentName - that should be departmentNumber.

pony10us: I just tried that but I get the same message.
0
 
RobSampsonCommented:
Hi, where is the department number attribute coming from?  I can't see it on the Organization tab of a user account.

You already have department being returned, so if you just use:
objCom.CommandText ="select name,telephonenumber,mobile,mail,company,title,department,sAMAccountName,sn,userAccountControl,msexchhidefromaddresslists FROM 'GC://"+objADsPath+"' where sAMAccountName='xxxxxx' and objectCategory='Person' AND objectClass = 'USER' ORDER by sAMAccountname"

then you should be able to retrieve
objRecordSet.Fields("department")

Rob.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
MegGraceAuthor Commented:
I am pretty sure it is a default attribute. Here is MS's list and it is there:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms675090(v=vs.85).aspx

I can get department, but I need to filter by the departmentNumber, as the department name isn't always consistent. Thanks.
0
 
MegGraceAuthor Commented:
I should also note that this is currently working in ColdFusion (cfldap), but need to migrate to asp.  Thanks.
0
 
pony10usCommented:
Have you tried to move them around and see if that helps?  Put the departmentNumber right after department?
0
 
pony10usCommented:
You may also want to take a look at this:   http://blogs.msdn.com/b/tehnoonr/archive/2010/11/22/mapping-user-profile-properties-in-sharepoint-2010-to-ldap-attributes.aspx

It seems that departmentNumber is a "missing attribute" at least for Sharepoint.
0
 
MegGraceAuthor Commented:
I think you are correct. I have found I can get that information from our employee database, rather than AD, so I will go that much easier route. Thank you for time and help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now