Solved

Script to query user accounts in AD

Posted on 2014-04-02
11
512 Views
Last Modified: 2014-04-03
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.
0
Comment
Question by:mystikal1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 39972355
import-module ac* 
Get-ADUser -Filter * | export-csv c:\filename.csv

Open in new window

0
 
LVL 19

Expert Comment

by:Kash
ID: 39972368
import-module *activedir*

get-aduser -filter * -SearchBase "DC=mydomain, DC=local" | format-table name,surname | out-file exported.csv
0
 
LVL 1

Author Comment

by:mystikal1000
ID: 39972482
Where does it read a list of user accounts from these powershell commands??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:becraig
ID: 39972504
Get-aduser looks fit for active directory users.

Filter * says all users
0
 
LVL 1

Author Comment

by:mystikal1000
ID: 39972541
I know, but I want it to read certain AD accounts :)
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39972843
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
 
LVL 1

Author Comment

by:mystikal1000
ID: 39973430
Awesome Billprew!!!
0
 
LVL 2

Expert Comment

by:MilesLogan
ID: 39973928
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
 
LVL 17

Expert Comment

by:Premkumar Yogeswaran
ID: 39974718
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
 
LVL 1

Author Comment

by:mystikal1000
ID: 39974821
Didn't work...
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39975029
Thanks, glad that was useful.

~bp
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
A hard and fast method for reducing Active Directory Administrators members.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question