Hi All<\/p>\n
i have email addresses in csv format, i want to export their samaccount names and UPNs to a csv file i am using the below syntax but i am not getting the output. please guide me<\/p>\n
$list = Import-Csv C:\\temp\\list.csv\nForEach($user in $list){ \n$dn = $user.user\nGet-ADUser -Filter { displayName -like $dn } -Properties *| Select samaccountname,displayname,UserPrincipalName |Export-Csv C:\\temp\\export.csv -NoType -Append } \n<\/code><\/pre>","upvoteCount":6,"answerCount":4,"datePublished":"2021-09-03T15:40:42.000Z","author":{"@type":"Person","name":"risingflight","url":"https://community.spiceworks.com/u/risingflight"},"acceptedAnswer":{"@type":"Answer","text":"
Advertisement
Technically, nobody can help you. You haven’t shared with us the format of the users in your csv file - so we have no idea what you’re defining in line 3 and comparing in line 4.<\/p>\n
But if you have email addresses in a csv file, you probably don’t want to compare them to a “display name”. We’ll have to see how you reply/revise the post to know for sure.<\/p>","upvoteCount":0,"datePublished":"2021-09-03T15:56:25.000Z","url":"https://community.spiceworks.com/t/get-aduser-filter/810236/2","author":{"@type":"Person","name":"semicolon","url":"https://community.spiceworks.com/u/semicolon"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi All<\/p>\n
i have email addresses in csv format, i want to export their samaccount names and UPNs to a csv file i am using the below syntax but i am not getting the output. please guide me<\/p>\n
$list = Import-Csv C:\\temp\\list.csv\nForEach($user in $list){ \n$dn = $user.user\nGet-ADUser -Filter { displayName -like $dn } -Properties *| Select samaccountname,displayname,UserPrincipalName |Export-Csv C:\\temp\\export.csv -NoType -Append } \n<\/code><\/pre>","upvoteCount":6,"datePublished":"2021-09-03T15:40:43.000Z","url":"https://community.spiceworks.com/t/get-aduser-filter/810236/1","author":{"@type":"Person","name":"risingflight","url":"https://community.spiceworks.com/u/risingflight"}},{"@type":"Answer","text":"i have users in the below format<\/p>\n
user
\n[email protected]<\/a>
\n[email protected]<\/a><\/p>","upvoteCount":0,"datePublished":"2021-09-03T16:08:32.000Z","url":"https://community.spiceworks.com/t/get-aduser-filter/810236/3","author":{"@type":"Person","name":"risingflight","url":"https://community.spiceworks.com/u/risingflight"}},{"@type":"Answer","text":"Alright so (with the first entry) what you’re effectively doing on line 4 is → Get-ADUser -filter { displayname -like “[email protected]<\/a>” }<\/p>\nThat’s not going to find anybody. So if you change the comparison to something like: { mail -eq “[email protected]<\/a>” }, or in your case specifically { mail -eq $dn }, I think you’ll find that the script should start working.<\/p>\n
\n*** Really getting annoyed with this “not being able to use multiple code blocks thing” ***<\/em><\/p>","upvoteCount":0,"datePublished":"2021-09-03T16:17:56.000Z","url":"https://community.spiceworks.com/t/get-aduser-filter/810236/4","author":{"@type":"Person","name":"semicolon","url":"https://community.spiceworks.com/u/semicolon"}}]}}