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
Solved

Script to query user accounts in AD

Posted on 2014-04-02
11
509 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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 53

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 53

Expert Comment

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

~bp
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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