Get-ADUser Powershell Command Tutorial To List Active Directory Users with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-aduser-powershell-command-tutorial-to-list-active-directory-users-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Windows Active Directory provides very useful enterprise user management capabilities. Powershell is new scripting language provides for Microsoft Operating systems. Get-ADUser is a very useful command or commandlet which can be used to list Active Directory users in different ways.

List Domain Users Interactively

We will start with a simple example. We will list all domain users. In this example, we will do not provide any option or parameter to the Get-ADUser command. But after running command we will be asked for a filter. We will provide asterisk * as a filter which means all users.

List Domain Users Interactively
List Domain Users Interactively

List Domain Users

In this example, we will list all domain users by providing the asterisk as parameter * to the Get-ADUser  command. We will use -Filter option.

List Domain Users 
List Domain Users 

List All Users In A Container or OU

As an enterprise environment has a lot of users with different departments, containers, and OU we may need to list only given department, container or OU. We will use -SearchBase option and provide the OU to filter users. In this example, we will use DC=ABC, DC=LOCAL

List All Users In A Container or OU
List All Users In A Container or OU

Filter Users By Username

We can filter users by their username. We will use a query language which will specify the name in Powershell. We will also use -Filter option. In this example, we will list users whose usernames start with H letter.

Filter Users By Username
Filter Users By Username

Get All Properties

As Active Directory is a very complex environment there are a lot of attributes and properties about users. By default, only some of them are printed like Name, SID, Surname, GivenName etc. We can also list all of these attributes with the -Properties command and asterisk *.

Get All Properties
Get All Properties

As we can see from the screenshot that properties like AccountExpirationDate, AccountLockoutTime, … are printed.

LEARN MORE  How To Run gpupdate /force On Windows?

Filter and Show Specific Properties

As there are a lot of properties and by default, only some of them are printed we may need specific properties to be printed. We can print specific property or attribute by specifying with the -Property option like below. We will print properties like BadLogonCount, Title etc.

Filter and Show Specific Properties
Filter and Show Specific Properties

Show Properties For Specific User

We can also show properties of the given or specific user we need to provide the username to the -Filter option and the properties or attributes we want to show.

Show Properties For Specific User
Show Properties For Specific User

Export To CSV File

If we ware working with 3rd party systems and provide Active Directory user data we can use CSV format. We can export the Active Directory User data in CSV to a file with the Export-CSV command like below. We will also provide the CSV file name and path which is ADUsers.csv in this example.

Export To CSV File
Export To CSV File

Print Email Address

Email address information also printed with the Get-ADUser command. We will just provide the email as the property we want to print.

List Only Enabled Users

Active Directory users can be disabled for different reasons like Security. So after a user account is disabled its Enabled property will be set to false. If we need to list only enabled users and filter out disabled users we can use Enabled -eq $True filter.

LEARN MORE  How To Add A User To A Group?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-aduser-powershell-command-tutorial-to-list-active-directory-users-with-examples/
PINTEREST
PINTEREST
INSTAGRAM