Script to query user accounts in AD

I need a script that will read a list of user accounts in a txt file and it will export all of the users information from the AD account (general tab) into a file per line for each account.  Prefer a csv file.
LVL 1
mystikal1000Asked:
Who is Participating?
 
Bill PrewCommented:
Here's a simple example of doing it with a BAT script that reads the users from the test file one at a time, queries AD using the powerful (and free) ADFIND utility (link below), and outputs whatever fields you desire to a single CSV file.

http://www.joeware.net/freetools/tools/adfind/

@echo off

set UserList=users.txt
set OutFile=adinfo.csv

(
  for /f "usebackq" %%A in ("%UserList%") do (
    adfind -csv -f "(sAMAccountName=%%A)" cn sn name givenname displayname mail telephoneNumber title departmentcode sAMAccountName
  )
) > "%OutFile%"

Open in new window

0
 
becraigCommented:
import-module ac* 
Get-ADUser -Filter * | export-csv c:\filename.csv

Open in new window

0
 
Kash2nd Line EngineerCommented:
import-module *activedir*

get-aduser -filter * -SearchBase "DC=mydomain, DC=local" | format-table name,surname | out-file exported.csv
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mystikal1000Author Commented:
Where does it read a list of user accounts from these powershell commands??
0
 
becraigCommented:
Get-aduser looks fit for active directory users.

Filter * says all users
0
 
mystikal1000Author Commented:
I know, but I want it to read certain AD accounts :)
0
 
mystikal1000Author Commented:
Awesome Billprew!!!
0
 
MilesLoganCommented:
You could also do something like ..

gc users.txt | Get-ADUser -Properties * | select GivenName,Initials,Surname,DisplayName,Description,Office,telephoneNumber,mail,HomePage | export-csv data.csv -nti
0
 
Premkumar YogeswaranAnalyst II - System AdministratorCommented:
Hi,

Please use the below powershell script

You need to provide the input as users.csv

Header should be User example below (samid )

User
ravia
premk
shyamk


import-module activedirectory
import-csv c:\temp\users.csv | % { Get-ADUser $_.user -properties * | export-csv c:\filename.csv -notype }

Open in new window

0
 
mystikal1000Author Commented:
Didn't work...
0
 
Bill PrewCommented:
Thanks, glad that was useful.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.