Home » PowerShell » Query Active Directory Users Info Using PowerShell

Query Active Directory Users Info Using PowerShell

Many times administrators want to quickly query active directory users’ account and account properties. PowerShell provides an Active Directory module to manage objects in Active Directory, administer domain and get information about active directory computers, user accounts, groups, etc.

ActiveDirectory PowerShell module has group of cmdlets. These cmdlets are used to manage Active Directory domain, Active Directory Database mounting tool instances, Active Directory Lightweight Directory Services and many more.

Query Active Directory Users information using PowerShell to query for user accounts using Get-AdUser cmdlet. Get-AdUser cmdlets gets a specific user object or get multiple user objects based on search criteria.

It requires ActiveDirectory add-on module to be installed. If you don’t have installed, refer this link to Check and Install module. if not exists.

If you like to work on Windows PowerShell Integrated Scripting Environment(ISE), type ISE at startup and click on Windows PowerShell ISE app to open it:

ActiveDirectory module loaded?

Load Import-module ActiveDirectory

Run below command to load Active Directory module, you can use its cmdlets afterwards.

Import-module ActiveDirectory

Use below cmdlets to query Active Directory (AD) for User Accounts

To View All Active Directory Commands available

get-command -Module ActiveDirectory

Get-AdUser Examples

Get User and List All Properties (attributes)

Get-ADUser -Identity JohnSmith -Properties *

In the above command, Get-ADUser returns the user and its properties filter by its distinguished name.

Cool Tip: Get aduser attributes from csv in PowerShell!

Get All Active Directory Users in Domain

Get-ADUser -Filter *

Get a List of All Users from a Specific OU

Get-ADUser -SearchBase "OU=ShellGEEK Users,dc=ad,dc=shellgeek.com" -Filter *

Cool Tip: Learn how to get aduser using userprincipalname!

Get a List of All Users with Last name “Smith”

Get-ADUser -Filter {Surname -eq "Smith"} -SearchBase "DC=ad,DC=company,DC=com"

Export email addresses for all user accounts to a CSV file

Get-ADUser -Filter *  -SearchBase "DC=ad,DC=company,DC=com" -Properties mail | Select mail | Export-CSV -path C:\UserEmailAddress.csv -NoTypeInformation

In the above command, Get-ADUser command gets all user accounts filter by domain and export it to csv file.

Cool Tip: Do you know equivalent of cat command in Windows!

Conclusion

I hope above article help you to understand about query Active Directory Users information using PowerShell. ActiveDirectory PowerShell module provides many more User accounts related cmdlets, we will explore it in our next article.

You can also find additional Get-AdUser examples using below command:

Get-Help Get-AdUser -examples

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.