Home » Dsquery » Dsquery User Email Address Examples

Dsquery User Email Address Examples

Dsquery user command finds the user in the active directory that matches the specified search criteria. Active Directory user has mail attribute which stores email-address for the user.

dsquery find the user by email address
dsquery find the user by email address

Dsget user command-line tool displays the properties of the user in the directory. It has an email parameter that displays the email address.

In this tutorial, we will discuss how to use the dsquery user command to get user email address and use the dsquery command to find the user by email address.

Dsquery – Get User Email Address

Using the dsquery user command with the specified distinguished name of the user, it finds the user in the active directory. It pipes the user properties to the dsget user command that uses the mail parameter to display the email address of the user.

dsquery user "CN=Chris Dore,OU=SALES,DC=SHELLPRO,DC=LOCAL" | dsget user -display -email

In the above dsquery user email address example, it gets the user email address and user display name.

C:\Windows\system32>dsquery user "CN=Chris Dore,OU=SALES,DC=SHELLPRO,DC=LOCAL" | dsget user -display -email
  display       email
  Chris Dore    [email protected]
dsget succeeded

C:\Windows\system32>

Use dsquery to Find User by Email Address

Use the general version of the dsquery * command to search user by email address and find the user display name and samaccountname.

In the below example, the dsquery * command uses the filter to specify the search criteria. dsquery command searches the user by the email address in the directory and gets the user object.

dsquery * -filter "mail= [email protected]" -attr displayname samaccountname

The output of the above dsquery command to get the user by email address using dsquery is:


C:\Windows\system32>dsquery * -filter "mail= [email protected]" -attr displayname samaccountname
  displayname    samaccountname
  Tom Smith      toms

C:\Windows\system32>

Dsquery Group Members Email Address

Use the dsquery group command to get the group in the active directory. It pipes the result to the dsget group command to get all the members of the group like users. It pipes the results to the dsget user command to get the group members’ email addresses.

dsquery group CN=SALESLeader,OU=SALES,DC=SHELLPRO,DC=LOCAL | dsget group -members | dsget user -display -email

The output of the above command gets the group member’s email address using the dsquery.

dsquery group members email address
dsquery group member’s email address

Conclusion

I hope the above article to use dsquery user to find the user email address and search the user by the email address is helpful to you.

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