header image

Outputting AD data to CSV

Posted by: | December 17, 2015 Comments Off on Outputting AD data to CSV |

 

Back in this post https://richardspowershellblog.wordpress.com/2014/12/29/using-givenname-and-surname-instead-of-samaccountname/

I showed how to get AD information using afirst and last names rather than the samAccountName.

 

A question came up about reading from a CSV containing a list of names and outputting the results to another CSV.

 

My preference would be to create a single PowerShell pipeline.

Import-Csv -Path ./adtest.csv |
foreach  {
$fname = $psitem.GivenName
$lname = $psitem.Surname
Get-ADUser -Filter {GivenName -eq $fname -and Surname -eq $lname} -Properties * |
select SamAccountName, Division, Office, City
} |
Export-Csv aduserslist.csv –NoTypeInformation

 

Read the CSV and pipe to foreach. Get the data and push onto pipeline. Export to CSV.

under: PowerShell and Active Directory

Comments are closed.

Categories