The Get-ADUser command helps you find and see information about users in your Active Directory. It makes it easy to get details about people in your network.
Get-ADUser in PowerShell
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
PowerShell
Get-ADUser [-Identity] <User> [-Properties <String[]>] [-Filter <String>] [-SearchBase <String>] [-SearchScope <String>] [-Server <String>] [-Credential <PSCredential>] [-ResultSetSize <Int>] [-SortBy <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
-Identity is used to specify a single user by name, username, or distinguished name.
-Filter lets you search for users matching conditions, like all users in a city.
Examples
PowerShell
Get-ADUser -Identity "jdoe"PowerShell
Get-ADUser -Filter "Name -like '*Smith*'"PowerShell
Get-ADUser -Filter * -Properties EmailAddress
Sample Program
This script loads the Active Directory module, gets the user named 'alice', and prints her name, email, and department.
PowerShell
Import-Module ActiveDirectory # Get user with username 'alice' $user = Get-ADUser -Identity alice -Properties EmailAddress, Department Write-Output "User: $($user.Name)" Write-Output "Email: $($user.EmailAddress)" Write-Output "Department: $($user.Department)"
Important Notes
You need to run this command on a computer joined to the Active Directory domain.
Make sure you have permission to read user information in Active Directory.
Use -Properties to get extra details, otherwise only basic info is returned.
Summary
Get-ADUser helps you find and view user info in Active Directory.
Use -Identity for one user or -Filter to search many users.
Remember to add -Properties to see more details about users.
Practice
1. What does the
Get-ADUser cmdlet do in PowerShell?easy
Solution
Step 1: Understand the purpose of Get-ADUser
The cmdlet is designed to fetch or retrieve user information from Active Directory.Step 2: Compare with other cmdlets
Creating, deleting, or modifying users are done by other cmdlets like New-ADUser or Set-ADUser, not Get-ADUser.Final Answer:
Retrieves information about Active Directory users -> Option BQuick Check:
Get-ADUser = Retrieve user info [OK]
Hint: Get-ADUser always fetches user info, not changes [OK]
Common Mistakes:
- Confusing Get-ADUser with New-ADUser
- Thinking it modifies user data
- Assuming it deletes users
2. Which of the following is the correct syntax to get a user by their username using
Get-ADUser?easy
Solution
Step 1: Identify the correct parameter for a single user
The-Identityparameter is used to specify a single user by username or distinguished name.Step 2: Check other parameters
Parameters like-Name,-UserName, or-Userare not valid for Get-ADUser to specify a single user.Final Answer:
Get-ADUser -Identity "jdoe" -> Option AQuick Check:
-Identity = single user [OK]
Hint: Use -Identity to specify one user by username [OK]
Common Mistakes:
- Using -Name instead of -Identity
- Trying -UserName which is invalid
- Confusing parameter names
3. What will this command output?
Get-ADUser -Filter 'Enabled -eq $true' -Properties EmailAddress | Select-Object Name, EmailAddress
medium
Solution
Step 1: Understand the filter condition
The filterEnabled -eq $trueselects only users who are enabled (active).Step 2: Check properties and output
The command requests theEmailAddressproperty and selects to displayNameandEmailAddressfor each user.Final Answer:
List of enabled users with their names and email addresses -> Option CQuick Check:
Filter enabled + EmailAddress shown = List of enabled users with their names and email addresses [OK]
Hint: Filter enabled users and add -Properties for extra fields [OK]
Common Mistakes:
- Forgetting to add -Properties EmailAddress
- Assuming it lists disabled users
- Thinking EmailAddress is invalid property
4. You run this command but get an error:
What is the likely cause?
Get-ADUser -Filter "Name -like '*Smith'" -Properties Email
What is the likely cause?
medium
Solution
Step 1: Check the property name
The correct property for user email isEmailAddress, notEmail.Step 2: Validate filter and parameters
The filter syntax is valid and filtering by Name is allowed. The -Identity parameter is not required when using -Filter.Final Answer:
The property 'Email' does not exist; it should be 'EmailAddress' -> Option AQuick Check:
Wrong property name causes error [OK]
Hint: Use correct property names like EmailAddress, not Email [OK]
Common Mistakes:
- Using wrong property names
- Misunderstanding filter syntax
- Thinking -Identity is mandatory with -Filter
5. You want to list all users in the 'Sales' department with their names and phone numbers. Which command will do this correctly?
hard
Solution
Step 1: Use correct filter syntax for department
The filterDepartment -eq "Sales"correctly matches users in Sales department.Step 2: Include correct property and select output
Use-Properties TelephoneNumberto get phone numbers, then selectNameandTelephoneNumberfor output.Step 3: Check other options for errors
Get-ADUser -Identity 'Sales' -Properties Phone | Select Name, Phone uses -Identity incorrectly and wrong property names. Get-ADUser -Filter 'Department -like Sales' | Select Name, PhoneNumber has wrong filter syntax and property names. Get-ADUser -Filter 'Department = Sales' -Properties PhoneNumber | Select-Object Name, PhoneNumber uses '=' instead of '-eq' and wrong property names.Final Answer:
Get-ADUser -Filter 'Department -eq "Sales"' -Properties TelephoneNumber | Select-Object Name, TelephoneNumber -> Option DQuick Check:
Filter with -eq + correct property = Get-ADUser -Filter 'Department -eq "Sales"' -Properties TelephoneNumber | Select-Object Name, TelephoneNumber [OK]
Hint: Use -Filter with -eq and add -Properties for extra fields [OK]
Common Mistakes:
- Using wrong filter operators like '='
- Wrong property names like Phone instead of TelephoneNumber
- Misusing -Identity for filtering
