Extartcting users SMTP addresses

I need to query ad and extract users by display name  and sammaccount and show howmany smtp addresses they have under their account
gd6627Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Zaheer IqbalTechnical Assurance & ImplementationCommented:
You can do this via the Exchange Management Shell if you have access

Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses | Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}} | Export-CSV c:\EmailAddresses.csv -NoTypeInformation -Encoding Unicode
0
gd6627Author Commented:
no I don't have exchange console I have an extended schema and I can see the proxy address for primary and alias smtp
0
FOXActive Directory/Exchange EngineerCommented:
Create a folder named Temp on your c:drive
Run the following command

Get-Aduser -filter * -properties Displayname,Samaccountname,proxyaddresses | Select DisplayName,SamAccountname,Proxyaddresses | Export-csv 'c:\temp\UserResults.csv' -notypeinformation
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

gd6627Author Commented:
Hey Fox , Thanks for your repluy but the output CSV does not list the Proxy addressess

see below

Displayname       SamAccountname      Proxyaddresses
      guest-disabled      Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
      localadmin      Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
      krbtgt      Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
0
FOXActive Directory/Exchange EngineerCommented:
Where are you running the command from?  This command should be run against AD, this command was not run in Exchange Management Shell. Did you open powershell as an administrator?
0
gd6627Author Commented:
Running it from my ISE ps Console i loaded the Actiuve Directory Module . I dont have exchange on Prem am looking at the ADUC properties for the Proxy address and some users have 2 proxy addresses .

When i run the script without exporting the results i see the proxy address its only when i enable the Export that it comes out like that
0
Michael B. SmithManaging ConsultantCommented:
This is what I came up with:

$r = Get-ADUser -Filter * -Properties DisplayName, SamAccountName, EmailAddress, ProxyAddresses | Select DisplayName, SamAccountname, EmailAddress, @{ N = 'Addresses'; E = { $rrr = $_.ProxyAddresses |? { $_.SubString( 0, 5 ) -ceq 'smtp:' }; $rrr -join ';' } }
$r |? { $_.EmailAddress -and !$_.SamAccountName.StartsWith( 'SM_' ) -and !$_.SamAccountName.StartsWith( 'HealthMailbox' ) }

Open in new window

If you want to export it to a CSV add this to the end of the command:
| Export-CSV -NoTypeInformation <filename.csv>

Open in new window

0

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
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
Powershell

From novice to tech pro — start learning today.