Get attributes from Active Directory

      No Comments on Get attributes from Active Directory

It is very often that someone has a list of users or email addresses and wants something from active directory for that particular list.
Can be either homedrive or if the accounts are enabled, first name, last name, anyway endless attributes can be requested!

Here is a simple example on how to get the users name from their AD account. Obviously this can be changed to get other attributes or all of them really.

$data=import-csv .\c.csv -Delimiter ","

foreach ($row in $data) {
$temp=get-aduser $row.User -properties GivenName
write-host $temp.Givenname

$row.Name=$temp.GivenName
}

C.csv has two columns, User and Name. At the end of the script you will end up with a $data array containing also the GivenName attribute.

We can then export it to a file $data | export-csv .\filename.csv -NoTypeInformation

Leave a Reply

Your email address will not be published. Required fields are marked *