Solved

Getting/Filtering on departmentNumber in AD query in vbscript

Posted on 2012-04-12
8
1,821 Views
Last Modified: 2012-04-13
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
Comment
Question by:MegGrace
  • 4
  • 3
8 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 37840211
Try using just "department" (without the quotes)
0
 

Author Comment

by:MegGrace
ID: 37840232
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 37840733
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
 

Author Comment

by:MegGrace
ID: 37843017
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:MegGrace
ID: 37843183
I should also note that this is currently working in ColdFusion (cfldap), but need to migrate to asp.  Thanks.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 37843199
Have you tried to move them around and see if that helps?  Put the departmentNumber right after department?
0
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
ID: 37843382
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
 

Author Closing Comment

by:MegGrace
ID: 37844180
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now