Import Active Directory Module to ADPowerShell:
AD PowerShell module is installed by default on a DC.
To make sure that you have the Active Directory module available for import, you can run the following command in Windows PowerShell console.
Get-Module –ListAvailable
Open PowerShell console and load the Active Directory module with
Cmdlet Import-Module ActiveDirectory
After import ActiveDirectory Module
To get all user objects in Active Directory Get-ADuser –Filter *
Get-ADuser –Filter | Export-Csv c:\Aduserslist .csv
To export ad users list to c:\ drive filename given as Aduserslist.csv (it can be any name)
It can open with Microsoft Excel
To get specific OU users List:
Ex: To get the marketing users list
Get-ADuser -Filter * -SearchBase “OU=Marketing, DC=abc,DC=com”
To export CSV.
Get-ADuser -Filter * -SearchBase “OU=Marketing, DC=abc,DC=com” | Export-Csv c:\Marketing.csv
To get specific sub OU / child OU users List:
Get-ADuser -Filter * -SearchBase “OU=Branch,OU=sales,OU=abc,DC=abc,DC=com” | Export-Csv c:\Marketing.csv
To get the report of sub OU under child OU the reverse hierarchical structure has to be follow …
Referring to the following command
Get-ADuser -Filter * -SearchBase “OU=OU=Branch,OU=sales,OU=abc,DC=abc,DC=com”
i.e first we select the OU which report we are generating (EX: BRANCH), then select the upper level OU child OU (Ex: SALES)
then Parent OU (Ex: ABC)