AD users list generate & Export using PowerShell in windows2008R2, Windows 2012 Domain

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 

1

Open PowerShell console and load the Active Directory module with

Cmdlet Import-Module ActiveDirectory

Featured image

After import ActiveDirectory Module


To get all user objects in Active Directory  Get-ADuser  –Filter  *

Get-ADuser –Filter  | Export-Csv c:\Aduserslist .csv         

 Featured image

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”Featured image

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:

ps

 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”

6

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)

Leave a comment