Home » Dsquery » Using Dsquery to Get User Display Name

Using Dsquery to Get User Display Name

A User Display name in an Active Directory is a combination of users’ first name and last name but it can be set to any string. For example, “John Paul”. Active Directory user has displayname attribute.

Use the dsquery command to get the user display name. We can get user display name using the general version of the dsquery * command or the dsquery user command.

In this article, we will discuss how to get user display names using the dsquery command.

Dsquery get user displayname

Using the general version of the query command, dsquery *, the user displayname in the active directory can be retrieved.

dsquery * -filter "samaccountname=admin" -attr displayname

In the above command, we have used dsquery * to get user displayname using the specified search criteria in the filter parameter.

It gets the user displayname for the user where samaccountname = admin and display using attribute displayname.

The output of the above command to retrieve user displayname using the dsquery command is:

dsquery - get user display name
dsquery – get user display name

It prints the active directory user display name as John Paul on the terminal.

Using dsquery user to get user display name

dsquery user command is used to find user objects in the active directory for the specified search criteria.

Using the dsquery user command, it can get user display name, and to display user information, use the dsget user command.

dsquery user -name admin | dsget user -display

In the above command, we have used the dsquery user command to find the user objects in the active directory where the name is equal to admin. It passes the output to another dsget user command to display the user display name.

The output of the above command to get user display name and display on the terminal as:

dsget get user display name
dsget get user display name

Cool Tip: How to get the user lastlogon using the dsquery!

Conclusion

I hope the above article on how to get user display name using the dsquery * command and dsquery user command is helpful to you.

Dsget is also a command-line tool that is available on a Windows server or available if the system has AD DS (Active Directory Domain Services) installed. It gets the properties of a user in the active directory.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment