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.
0
0
Get-ADUser in PowerShell
Introduction
You want to check details of a specific user in your company network.
You need to list all users in a certain department or group.
You want to find users who have not logged in recently.
You need to export user information for reports or audits.
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
Gets the user with username 'jdoe'.
PowerShell
Get-ADUser -Identity "jdoe"Finds all users whose name contains 'Smith'.
PowerShell
Get-ADUser -Filter "Name -like '*Smith*'"Gets all users and shows their email addresses.
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)"
OutputSuccess
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.