Hi there,
I am trying to write a script to read a list of displaynames (h:\fullnames.txt) and return the samaccountname for each entry. I am dealing with AD user objects. The script I wrote below works, but the output is a bit ugly. It prints the headings samaccountname and displayname for each user. It would be better if I could just get the headings once and then the useful output below it.
Can you please tell me how I can modify the below script to do this?
$users = Get-Content h:\fullnames.txt
foreach ($user in $users)
{
get-aduser -ldapfilter "(displayname=$user)" -property samaccountname,displayname | Select-Object -Property samaccountname,displayname | out-file h:\fullnames_result500.txt -append
}