MegGrace
asked on
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("defaultNami ngContext" )
Set objDomain = Nothing
Set objConn = Server.CreateObject("ADODB .Connectio n")
objConn.provider ="ADsDSOObject"
objConn.Properties("User ID") = "xxxxxx" 'domain account with read access to LDAP
objConn.Properties("Passwo rd") = "xxxxxx" 'domain account password
objConn.Properties("Encryp t Password") = True
objConn.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Comman d")
Set objCom.ActiveConnection = objConn
objCom.CommandText ="select name,telephonenumber,mobil e,mail,com pany,title ,departmen t,sAMAccou ntName,sn, userAccoun tControl,m sexchhidef romaddress lists,depa rtmentNumb er 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.
Response.Write objRS("name")
My query is:
Set objDomain = GetObject ("GC://RootDSE")
objADsPath = objDomain.Get("defaultNami
Set objDomain = Nothing
Set objConn = Server.CreateObject("ADODB
objConn.provider ="ADsDSOObject"
objConn.Properties("User ID") = "xxxxxx" 'domain account with read access to LDAP
objConn.Properties("Passwo
objConn.Properties("Encryp
objConn.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Comman
Set objCom.ActiveConnection = objConn
objCom.CommandText ="select name,telephonenumber,mobil
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.
Try using just "department" (without the quotes)
ASKER
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.
pony10us: I just tried that but I get the same message.
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,mobil e,mail,com pany,title ,departmen t,sAMAccou ntName,sn, userAccoun tControl,m sexchhidef romaddress lists FROM 'GC://"+objADsPath+"' where sAMAccountName='xxxxxx' and objectCategory='Person' AND objectClass = 'USER' ORDER by sAMAccountname"
then you should be able to retrieve
objRecordSet.Fields("depar tment")
Rob.
You already have department being returned, so if you just use:
objCom.CommandText ="select name,telephonenumber,mobil
then you should be able to retrieve
objRecordSet.Fields("depar
Rob.
ASKER
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.
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.
ASKER
I should also note that this is currently working in ColdFusion (cfldap), but need to migrate to asp. Thanks.
Have you tried to move them around and see if that helps? Put the departmentNumber right after department?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.