Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-ADUser with display name as a value

**I have list of users display name in CSV file and I am trying to get samAccountName and export it to CSV file but its not working, I understand that get-aduser doesnt accept display name as a value so I used filter but still not work help please:)

CSV file format

User

Amer, john
Doe, John
smith, john
**

$list = Import-Csv C:\export.csv
foreach ($user in $list) {
Get-ADUser -filter { DisplayName -eq "user.user" } | Select samAccountName | Export-csv C:\export1.csv
}
like image 414
Yallabina Avatar asked Oct 26 '25 15:10

Yallabina


1 Answers

Try

ForEach($user in $list{    
$dn = $user.user
Get-ADUser -Filter { displayName -like $dn } | Select samAccountName > C:\export1.csv}

Also verify your Display names from AD match what is in CSV. But this worked for me. At first I couldn't export to C directly so I exported CSV to C:\AD\export.csv

like image 142
jdbwizzard Avatar answered Oct 29 '25 18:10

jdbwizzard