Avatar of gd6627
Flag for United States of America asked on

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
PowershellActive Directory

Avatar of undefined
Last Comment
Michael B. Smith

8/22/2022 - Mon
Zaheer Iqbal

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

no I don't have exchange console I have an extended schema and I can see the proxy address for primary and alias smtp

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

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

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?

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Michael B. Smith

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question