Matching PrimarySMTPAddress with user logon name for exchange 2010

Hello to all,

I have a CSV file with PrimarySMTPAddress in one column from 100 or so users in my domain.  I need another CSV file exported that has a second column with user logon name matching my 100 or so emails.  What is the script that I need to run in exchange management shell to accomplish that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

timgreen7077Exchange EngineerCommented:
Ok, import your current csv file into the $userlist variable below, and that will allow your new required outlook to make the column and row of your current user smpt address, so you can just copy the info from one .csv file to the other and they should be in the same order.

$userlist = Import-Csv c:\temp\current.csv
foreach ($user in $userlist) {
$perms += @(get-mailbox -Identity $
$perms | select displayname, samaccountname | export-csv c:\temp\newresults.csv
WTHTechAuthor Commented:
i am submitting a picture of the error I got:

my csv file column header is called user and this is the only column in my csv file

error from script
WTHTechAuthor Commented:
I also made the script in one line
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

timgreen7077Exchange EngineerCommented:
I think the one liner isn't really correct. I would suggest to just type the script the way I created it and try.
timgreen7077Exchange EngineerCommented:
also change your header to 'name' so that you don't have to change script.
WTHTechAuthor Commented:
ok this is what I got:

i am posting a picture

It looks like the script hangs and the new file does not get created
WTHTechAuthor Commented:
And many thanks for all of your help...
timgreen7077Exchange EngineerCommented:
You have to be sure to press enter again. according to your screen shot you need to press enter again.
WTHTechAuthor Commented:
ok, I did press the enter one more time and i got this Warning a bunch or times.

WARNING: By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of items returned. To return all items, specify "-ResultSize Unlimited". Be aware that, depending on the actual number of items, returning all items can take a long time and consume a large amount of memory. Also, we don't recommend storing the results in a variable. Instead, pipe the results to another task or script to perform batch changes.

We have thousands of users and the script was taking a while so I stopped it with ctrl-c.  I can not bug down our exchange server.  What about " Instead, pipe the results to another task or script to perform batch changes."
timgreen7077Exchange EngineerCommented:
If you did this correctly it wouldn't search all the mailboxes  but only the 100 you have in the csv file. What do you consider a long time? This could take only a few minutes or so. That was a standard informational alert. I'm not sure what you are doing. Just start over and enter the script the way I sent it to you and you should be fine. Also just a note be sure you change the column header in your csv to 'Name', so that it will match what the script is looking at.
FOXActive Directory/Exchange EngineerCommented:
Fair enough.  We will go with your .csv file that has a header of PrimarySmtpAddress. Let's call it smtps.csv
Remember we have UserprincipalNames that can be used for webmail login and we have samaccountnames for Lan logins.  Let's pull it all.

Import-CSv 'c:\temp\smtps.csv' | %{Get-mailbox $_.PrimarySmtpAddress | Select PrimarySmtpAddress,UserPrincipalName,Samaccountname} | Export-Csv 'c:\temp\outresults.csv' -notypeinformation

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WTHTechAuthor Commented:
Fox, it worked perfectly, Thanks very much and very appreciated
FOXActive Directory/Exchange EngineerCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.