Search code examples
vbscriptattributesactive-directoryldap-query

How to query for dn in Active Directory below non-leaf user object when the child object has no attributes?


Basically, what I'm trying to accomplish is deleting a non-leaf user object from MS Active Directory. At some point in time, a few additional objects were put underneath these non-leaf user objects, so I am trying to query for all these objects underneath the base and remove them first.

Here is my query in VBScript:

qQuery = "<LDAP://[SERVERNAME]/[BASE_USER_OBJECT]>;" & _
"(objectCategory=*);dn

I am expecting this to return the dn of every object below my base user object. The script throws an "Unspecified Error".

If I change the requesting attributes to distinguishedName instead of dn, then it runs just fine and returns the distinguishedName attribute from a few of the child objects. The problem is that a majority of the child objects don't have this distinguishedName attribute, or ANY attribute for that matter.

Is there any way to query for the dn in VBScript?

Thank you for any help in advance!


Solution

  • Guaranteed the objects have a distinguishedName. It's mandatory. Do you have enough permission to see these objects?

    This link has a number of good examples for your situation - http://www.selfadsi.org/delete.htm.