The dsquery command is a Windows CMD command used to query Active Directory for information about objects. It is a powerful tool for system administrators and can be used to search for objects such as users, computers, groups, and organizational units. The dsquery command is available in Windows Server 2003, Windows Server 2008, Windows Server 2012, and Windows Server 2016.

What is the Syntax of the dsquery Command?

The syntax of the dsquery command is as follows:

  • dsquery [object] [options]

The object argument specifies the type of object to be queried. The available objects are:

  • user
  • computer
  • group
  • ou

The options argument specifies the options to be used when querying the object. The available options are:

  • -name
  • -samid
  • -desc
  • -upn
  • -sizelimit
  • -timelimit
  • -scope
  • -attr
  • -l
  • -r
  • -limit
  • -sort
  • -c
  • -p
  • -q
  • -filter
  • -gc

What are the Options for the dsquery Command?

The options for the dsquery command are as follows:

  • -name – This option is used to specify the name of the object to be queried.
  • -samid – This option is used to specify the Security Account Manager (SAM) ID of the object to be queried.
  • -desc – This option is used to specify the description of the object to be queried.
  • -upn – This option is used to specify the user principal name (UPN) of the object to be queried.
  • -sizelimit – This option is used to specify the maximum number of objects to be returned in the query.
  • -timelimit – This option is used to specify the maximum amount of time the query can take to execute.
  • -scope – This option is used to specify the scope of the query.
  • -attr – This option is used to specify the attributes of the object to be returned in the query.
  • -l – This option is used to specify the level of the query.
  • -r – This option is used to specify the recursive nature of the query.
  • -limit – This option is used to specify the maximum number of objects to be returned in the query.
  • -sort – This option is used to specify the sort order of the objects returned in the query.
  • -c – This option is used to specify the command to be executed when the query is complete.
  • -p – This option is used to specify the path of the object to be queried.
  • -q – This option is used to specify the query string.
  • -filter – This option is used to specify the filter to be applied to the query.
  • -gc – This option is used to specify the global catalog to be used for the query.

What are Some Examples of the dsquery Command?

The following are some examples of the dsquery command:

  • To query for all users in the domain, use the following command: dsquery user
  • To query for all computers in the domain, use the following command: dsquery computer
  • To query for all groups in the domain, use the following command: dsquery group
  • To query for all organizational units in the domain, use the following command: dsquery ou
  • To query for all users with the name “John” in the domain, use the following command: dsquery user -name John
  • To query for all users with the SAM ID “jsmith” in the domain, use the following command: dsquery user -samid jsmith
  • To query for all users with the description “System Administrator” in the domain, use the following command: dsquery user -desc “System Administrator”
  • To query for all users with the UPN “[email protected]” in the domain, use the following command: dsquery user -upn [email protected]
  • To query for all users with the name “John” and the description “System Administrator” in the domain, use the following command: dsquery user -name John -desc “System Administrator”

Conclusion

The dsquery command is a powerful tool for system administrators that can be used to query Active Directory for information about objects. It is available in Windows Server 2003, Windows Server 2008, Windows Server 2012, and Windows Server 2016. The syntax of the dsquery command is dsquery [object] [options], where the object argument specifies the type of object to be queried and the options argument specifies the options to be used when querying the object. The available options are -name, -samid, -desc, -upn, -sizelimit, -timelimit, -scope, -attr, -l, -r, -limit, -sort, -c, -p, -q, -filter, and -gc. Examples of the dsquery command include querying for all users, computers, groups, and organizational units in the domain, as well as querying for specific users based on name, SAM ID, description, and UPN.

Leave a Reply