Get-ADUser with display name as a value

两盒软妹~` 提交于 2019-12-11 12:20:00

问题


**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
}

回答1:


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



来源:https://stackoverflow.com/questions/35804713/get-aduser-with-display-name-as-a-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!