"Elvis" <> wrote in message
news:B26AAA71-046A-4EC4-A11E-...
> Hi,
>
> Does anyone have a custom Quesry for Active Directory that is able to find
> a
> "null" value for any attributes within AD. We are looking to use an
> existing
> Active Directory Attribute field but need to be certain that it is not
> being
> used. Is there a way to seach AD to verify which attributes are not being
> used by anyone?
>
> Thanks
>
> Elvis
I use ADO in VBScript programs to query AD. See this link for details:
http://www.rlmueller.net/ADOSearchTips.htm
Using the syntax and variables from the link, you can filter on objects
where a specified attribute has or has not been assigned a value. For
example, the filter for all users where the employeeID attribute has a value
would be:
strFilter = "(&(objectCategory=person)(objectClass=user(employ eeID=*))"
A VBScript program to find all users with a value assigned to employeeID
could be similar to below:
===========
Option Explicit
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN, strName
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on all users with value assigned to employeeID attribute.
strFilter = "(&(objectCategory=person)(objectClass=user)(emplo yeeID=*))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strDN = adoRecordset.Fields("distinguishedName").Value
strName = adoRecordset.Fields("sAMAccountName").Value
Wscript.Echo strDN & " (" & strName & ")"
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
===========
You can also use the same filter with adfind. For example:
adfind -default -f
"(&(objectCategory=person)(objectClass=user)(emplo yeeID=*))" sAMAccountName
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--