JSI Tip 7717. More on DSQUERY attribute filtering.

Jerold Schulman

February 1, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today


In tip 7714 What attribute names can I use with the user filtered dsquery command, I used attribute filtering to retrieve a list of user attributes.

The filter is NOT limited to one attribute.

If you wanted a report of distinguishedName department manager, you would use:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*))" -attr distinguishedName department manager -limit 0

If you wanted the same report, but only if the manager attribute was NOT NUL, use:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*)(manager=*))" -attr distinguishedName department manager -limit 0

If you wanted the same report, but only if the manager attribute AND the department attribute was NOT NUL, use:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*)(manager=*)(department=*))" -attr distinguishedName department manager -limit 0

if you wanted the same report, but only if the manager attribute AND the department attribute was NOT NUL, AND the user was located in the United States, use:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*)(manager=*)(department=*)(c=us))" -attr distinguishedName department manager -limit 0

If you wanted the above report, but only for departments that start with HDQ, use:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=*)(manager=*)(department=hdq*)(c=us))" -attr distinguishedName department manager -limit 0

If you wanted a list of Computers, showing their location, operatingSystem, operatingSystemVersion, and operatingSystemServicePack, use:

dsquery * domainroot -filter "(&(objectCategory=Computer)(objectClass=User))" -attr distinguishedName location operatingSystem operatingSystemVersion operatingSystemServicePack -limit 0

The above report would look similar to:

  distinguishedName                                   location                    operatingSystem              operatingSystemVersion    operatingSystemServicePack  CN=JSI001,OU=Domain Controllers,DC=JSIINC,DC=COM    HDQ - Computer Room         Windows Server 2003          5.2 (3790)                Service Pack 1, v.1137  CN=JSI007,CN=Computers,DC=JSIINC,DC=COM             HDQ - CFO                   Windows XP Professional      5.1 (2600)                Service Pack 1  CN=JSI009,CN=Computers,DC=JSIINC,DC=COM             HDQ - CEO                   Windows XP Professional      5.1 (2600)                Service Pack 2, v.2055  CN=JSI013,CN=Computers,DC=JSIINC,DC=COM             HDQ - Training Room         Windows 2000 Professional    5.0 (2195)                Service Pack 4  CN=JSI022,CN=Computers,DC=JSIINC,DC=COM             HDQ - Training Room         Windows XP Professional      5.1 (2600)                Service Pack 1



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like