Hi All

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

$list = Import-Csv C:\temp\list.csv
ForEach($user in $list){    
$dn = $user.user
Get-ADUser -Filter { displayName -like $dn } -Properties *| Select samaccountname,displayname,UserPrincipalName |Export-Csv C:\temp\export.csv -NoType -Append } 
6 Spice ups

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.

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.

i have users in the below format

user
user1@contoso.com
user2@contoso.com

Alright so (with the first entry) what you’re effectively doing on line 4 is → Get-ADUser -filter { displayname -like “user@contoso.com” }

That’s not going to find anybody. So if you change the comparison to something like: { mail -eq “user@contoso.com” }, or in your case specifically { mail -eq $dn }, I think you’ll find that the script should start working.


*** Really getting annoyed with this “not being able to use multiple code blocks thing” ***