How to Use Get-ADUser in PowerShell: Syntax and Examples
Use the
Get-ADUser cmdlet in PowerShell to retrieve user accounts from Active Directory. You can specify a username or filter criteria to get user details like name, email, and more.Syntax
The basic syntax of Get-ADUser includes specifying the user identity or using filters to find users. You can also select which properties to display.
-Identity: Specify a username or user object.-Filter: Use a query to find users matching conditions.-Properties: List additional user properties to retrieve.
powershell
Get-ADUser -Identity <username> [-Properties <property1,property2,...>]
Get-ADUser -Filter <filter-string> [-Properties <property1,property2,...>]Example
This example shows how to get a user by username and display their name and email address.
powershell
Get-ADUser -Identity jsmith -Properties EmailAddress | Select-Object Name, EmailAddress
Output
Name EmailAddress
---- ------------
John Smith jsmith@example.com
Common Pitfalls
Common mistakes include not importing the Active Directory module, using incorrect property names, or forgetting to specify -Properties to get extra details.
Also, using -Filter requires a string with proper syntax, not a script block.
powershell
Wrong:
Get-ADUser -Filter {Name -like "*smith*"}
Right:
Get-ADUser -Filter "Name -like '*smith*'" -Properties EmailAddress | Select-Object Name, EmailAddressQuick Reference
| Parameter | Description |
|---|---|
| -Identity | Specify a single user by username or distinguished name |
| -Filter | Find users matching a condition, e.g., "Name -like '*smith*'" |
| -Properties | List extra user properties to retrieve beyond defaults |
| Select-Object | Choose which properties to display in output |
Key Takeaways
Use Get-ADUser with -Identity or -Filter to find Active Directory users.
Add -Properties to retrieve extra user details like email or department.
Always import the Active Directory module before running Get-ADUser.
Use string syntax for -Filter, not script blocks.
Select only needed properties to keep output clear and fast.