AD Lookup via EmployeeID > Export user info to csv

Christian Hans
Christian Hans used Ask the Experts™
on
I have a CSV/TXT file with the heading of EmployeeID

How can I export a list to csv from AD that contains only the users listed in that EmployeeID file via powershell?

Example:
EmployeeID
3374
3550
3401

I want the command to find the EmployeeID "3374" (for example) and export the userprincipalname, displayname, samaccount etc...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Expert
Commented:
Import into powershell, then cycle through with a foreach.

$EmployeeIDs = import-csv -path 'path to csv'\employeeid.csv
$Users = @()
foreach ($EmployeeID in $EmployeeIDs) {
    $user = get-aduser -filter 'Employeeid -eq "$($employeeid)"' |select SamaccountName, UserPrincipleName, Name
    $users += $user
}
$users |export-csv -path 'path to export'\userdetails.csv -notypeinformation

Open in new window

ITSysTechSenior Systems Administrator

Commented:
In addition to using a powershell command. I would highly recommend using Active Directory Explorer, it is simple to use and will allow you to create your own search criterias with ease.
Daryl BamforthTechnical Expert

Commented:
Script will do as requested.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial