Extartcting users SMTP addresses

gd6627
gd6627 used Ask the Experts™
on
I need to query ad and extract users by display name  and sammaccount and show howmany smtp addresses they have under their account
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Zaheer IqbalTechnical Assurance & Implementation

Commented:
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

Author

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
FOXActive Directory/Exchange Engineer
Top Expert 2015

Commented:
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
Ensure you’re charging the right price for your IT

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

Author

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
FOXActive Directory/Exchange Engineer
Top Expert 2015

Commented:
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?

Author

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
Managing Consultant
Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial