How to Get AD User in PowerShell: Simple Commands and Examples
Use the
Get-ADUser cmdlet in PowerShell to retrieve Active Directory user information. You can specify a username or filter users with parameters like -Identity or -Filter to get the desired user details.Syntax
The basic syntax of Get-ADUser is:
Get-ADUser -Identity <username>: Gets a user by their username.Get-ADUser -Filter <filter_expression>: Gets users matching a filter.-Properties <property_list>: Specifies which user properties to retrieve.
This cmdlet requires the Active Directory module.
powershell
Get-ADUser -Identity <username> [-Properties <property1,property2,...>] Get-ADUser -Filter <filter_expression> [-Properties <property1,property2,...>]
Example
This example gets the user with username 'jdoe' and shows their name, email, and title.
powershell
Import-Module ActiveDirectory $user = Get-ADUser -Identity jdoe -Properties EmailAddress,Title $user | Select-Object Name, EmailAddress, Title
Output
Name EmailAddress Title
---- ------------ -----
jdoe jdoe@example.com Sales Manager
Common Pitfalls
Common mistakes include:
- Not importing the Active Directory module before running
Get-ADUser. - Using
-Identitywith a wrong or non-existent username. - Forgetting to specify
-Propertiesto get additional user details beyond the default. - Using incorrect filter syntax with
-Filter.
powershell
# Wrong: Missing module import
Get-ADUser -Identity jdoe
# Correct:
Import-Module ActiveDirectory
Get-ADUser -Identity jdoe -Properties EmailAddress,TitleQuick Reference
| Parameter | Description |
|---|---|
| -Identity | Get user by username or distinguished name |
| -Filter | Get users matching a filter, e.g. 'Name -like "*smith*"' |
| -Properties | Specify additional user properties to retrieve |
| -SearchBase | Limit search to a specific Active Directory container |
| -Server | Specify the domain controller to query |
Key Takeaways
Use Get-ADUser with -Identity to get a specific user by username.
Import the Active Directory module before running Get-ADUser.
Use -Properties to retrieve extra user details beyond defaults.
Use -Filter for flexible searches with conditions.
Check for typos in usernames and filter syntax to avoid errors.