Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script to query user accounts in AD

Posted on 2014-04-02
11
Medium Priority
?
517 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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
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 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

Expert Comment

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

~bp
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

877 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