Use the PowerShell Cmdlet Get-ADUser to display user accounts in Active Directory.
With Get-ADUser you can:
– Set filters
– Show specific attributes
– Export results in a CSV-file
AD PowerShell Basics
I created the series AD PowerShell Basics to show you how to use basic PowerShell commands – and how to get a lot of information from or to Active Directory with only a little effort and a small script. The following Cmdlets will be introduced:
New-ADUser
Get-ADUser
Set-ADUser
New-ADGroup, Get-ADGroup, Set-ADGroup
The Cmdlet Get-ADUser
Index
In the second part of the series AD PowerShell Basiscs we want to have a closer look at the cmdlet Get-ADUser. By using this cmdlet you can read out attributes of existing user accounts in Active Directory.
Similar to the cmdlet New-ADUser the identity of a user account, for example the sAMAccountname is the only thing you need to run a query.
This query could look like that:
1 |
Get-ADUser Thomas.Mueller |
You will now get all information about the user Thomas.Mueller. In the the screenshot you can see how this looks like:
Set a Filter
What if you don’t know the sAMAccountname of the user you are looking for? What if you want to search for several accounts? In these cases you can set a filtert o search for more than one user account.
Filter can be used in many various ways by adding the parameter “-Filter”.
You may use filters to search for specific attributes.
Search for Surname with Get-ADUser
1 |
Get-ADUser –Filter {Surname –eq Mueller} |
This filtered search will return all users with the family name „Mueller“.
Search for First Name
1 |
Get-ADUser –Filter {GivenName –eq thomas} |
With GivenName you receive all users with the first name “Thomas”.
Search with Wildcard (*)
Another useful query is to list all users of an Organizational Unit (OU). To do that, simply use the asterisk symbol * and define a OU you want to search with the parameter -Searchbase.
1 |
Get-ADUser –Filter * -Searchbase „OU=Testuser,DC=Company,DC=Com“ |
Show Additional Attributes
You may have recognized, that not all attributes are shown in the results (see screenshots). If you want to see more, let’s say the phone number (office phone) of a user you have to add the desired attribute to the query.
List more attributes with Get-ADUser an the Parameter “-Properties“:
1 |
Get-ADUser Thomas.Mueller –Properties Officephone |
This way, you can list any other filled attribute that of a user account.
It is of course also possible to list multiple additional attributes. Use the parameter “-Porperties” and add all the attributes you want to get – separated with a comma.
1 |
Get-ADUser Thomas.Mueller –Properties Officephone,l,streetAddress |
Bulk Export of AD User Data with Get-ADUser
Sometimes it is necessary to search for a bigger amount of user accounts. But the PowerShell result view is not really handy in this case. A great alternative way is to export the Get-ADUser search results into a .csv file.
To redirect the results of a search query to a csv-file you can pipe the results as follows.
Run a Get-ADUser query and pipe the output.
The export itself works with “export-csv“
1 |
Get-ADUser –Filter * -Searchbase „OU=Testuser,DC=Company,DC=Com“ | export-csv „c:\test\export.csv“ |
The exported CSV file will look like that:
I suggest to open the CSV file in Excel, because it is much better to use and you can easily filtert he results as you like.
This is a simple way to view a lot of user data at once. The script can help you to frequently query a bigger number of users in with certain attributes or set filters.
Comfortable User Search and Edit
If you want to search for single users or delegate the user maintenance tasks in Active Directory this method is not really comfortable. This is why we created a FirstWare IDM-Portal for this task. You can use FirstWare IDM-Portal for:
- Fast AD Administration
- Delegation
- Self Service and more
We would be happy to support you – Contact us if you would like to know more.
Leave a Reply
<p>Your email is safe with us.<br/>Information about our <a href="https://activedirectoryfaq.com/contact-us/">data protection policies</a></p>