Discussion:
Check if AD attribute exists
(too old to reply)
Craig
2007-06-14 12:52:54 UTC
Permalink
Hi, is there a way to check if an attribute of a user object in Active
Directory is "Not Set", i.e. currently has no values set?

Checking for Null or an empty string doesn't seem to be possible, but I
don't really want to rely on checking for an error.

many thanks,
Craig
J. Anos
2007-06-14 16:25:34 UTC
Permalink
checking for empty strings is perfectly possible. do it all the time.
howzabout posting the code that is failing?
Post by Craig
Hi, is there a way to check if an attribute of a user object in Active
Directory is "Not Set", i.e. currently has no values set?
Checking for Null or an empty string doesn't seem to be possible, but I
don't really want to rely on checking for an error.
many thanks,
Craig
Richard Mueller [MVP]
2007-06-14 16:38:09 UTC
Permalink
Also, you can use ADO to query AD for objects where either an attribute has
a value, or where the attribute is missing. For example:

(&(sAMAccountName=JimSmith)(employeeID=*))

will only return a record if user JimSmith has a value assigned to
employeeID. Otherwise, no records are returned. Or:

(&(sAMAccountName=JimSmith)(!employeeID=*))

will only return a record if user JimSmith does not have a value assigned to
the employeeID attribute. The RecordCount property of the Recordset object
can be used to check whether 0 or 1 record was retrieved. And, these queries
can be used in ADUC to filter objects in the display. You could filter for
all users that do not have a value assigned to employeeID with:

(&(objectCategory=person)(objectClass=user)(!employeeID=*))

For more on using ADO to search AD, see this link:

http://www.rlmueller.net/ADOSearchTips.htm
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Post by J. Anos
checking for empty strings is perfectly possible. do it all the time.
howzabout posting the code that is failing?
Post by Craig
Hi, is there a way to check if an attribute of a user object in Active
Directory is "Not Set", i.e. currently has no values set?
Checking for Null or an empty string doesn't seem to be possible, but I
don't really want to rely on checking for an error.
many thanks,
Craig
Craig
2007-06-14 18:28:12 UTC
Permalink
the below produces a type mismatch error. have I got the syntax wrong?

if not objUser.carLicense="" then
loop through the values
end if
Post by J. Anos
checking for empty strings is perfectly possible. do it all the time.
howzabout posting the code that is failing?
Post by Craig
Hi, is there a way to check if an attribute of a user object in Active
Directory is "Not Set", i.e. currently has no values set?
Checking for Null or an empty string doesn't seem to be possible, but
I don't really want to rely on checking for an error.
many thanks,
Craig
Richard Mueller [MVP]
2007-06-14 18:44:16 UTC
Permalink
When an attribute is not assigned a value, the value is neither blank nor
Null. You can use IsEmpty to check. For example:

If Not IsEmpty(objUser.carLicense) Then
' Loop.
End If
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Post by Craig
the below produces a type mismatch error. have I got the syntax wrong?
if not objUser.carLicense="" then
loop through the values
end if
Post by J. Anos
checking for empty strings is perfectly possible. do it all the time.
howzabout posting the code that is failing?
Post by Craig
Hi, is there a way to check if an attribute of a user object in Active
Directory is "Not Set", i.e. currently has no values set?
Checking for Null or an empty string doesn't seem to be possible, but I
don't really want to rely on checking for an error.
many thanks,
Craig
Craig
2007-06-14 19:01:35 UTC
Permalink
This is exactly what I've been looking for. Works a treat!

Many thanks Richard.
Post by Richard Mueller [MVP]
When an attribute is not assigned a value, the value is neither blank nor
If Not IsEmpty(objUser.carLicense) Then
' Loop.
End If
Continue reading on narkive:
Loading...