Get-ADUser Powershell Command Tutorial To List Active Directory Users with Examples
Windows Active Directory provides very useful enterprise user management capabilities. Powershell is a 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 the command we will be asked for a filter. We will provide asterisk *
as a filter which means all users.
1 |
PS> Get-ADUSer |

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.
1 |
PS> Get-ADUser -Filter * |

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
1 |
PS> Get-ADUser -Filter * -SearchBase "DC=ABC,DC=LOCAL" |

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.
1 |
PS> Get-ADUser -Filter 'Name -like "H*"' |

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 *
.
1 |
PS> Get-ADUser -Filter * -Properties * |

Get All Properties
As we can see from the screenshot that properties like AccountExpirationDate, AccountLockoutTime, … are printed.
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.
1 |
PS> Get-ADUser -Filter * -Properties "BadLogonCount","Title" |

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.
1 |
PS> Get-ADUser -Filter "Name -like 'İsmail Baydan'" -Properties "BadLogonCount","Title" |

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.
1 |
PS> Get-ADUser -Filter "*" | Export-CSV -Path ADUsers.csv |

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.
1 |
PS> Get-ADUser -Filter "*'" -Properties "EmailAddress" |
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.
1 |
PS> Get-ADUser -Filter {Enabled -eq $True} |
how to get AD user LOGON name to csv
Voila Poulpe :
get-aduser -filter * | select-object samaccountname | Out-File c:\USERAD2.csv
How to get the enabled users who have logged in in last 90 days. For legal reasons I cant disable some users.
Conrad
| export-csv c:\DIR_YOU_WANT\contacts.csv