Solved

Getting/Filtering on departmentNumber in AD query in vbscript

Posted on 2012-04-12
8
1,948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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
 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses

630 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