Get AD Users and Export to CSV

Powershell is not only making doing system administration tasks easy but also very effective and saves lot of time.

Instead of connecting to AD, searching for particular user and copying pasting contents. You can just use one line powershell script to do this for you.

Get-ADUser -Filter ‘*’ |  select SamAccountName, Department, Location | Export-Csv c:\temp\ADUsers.csv

Full script here

# Import Active Directory Module 
try 
{ 
    import-module activedirectory  
} 
catch 
{ 
    write-Output "Error while importing Active Directly module, please install AD Powershell modules first before running this script." 
} 
 
# Get AD Users and export results to CSV 
Get-ADUser -Filter '*' |  select SamAccountName, Department, Location | Export-Csv c:\temp\ADUsers.csv

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s