We help IT Professionals succeed at work.

Extartcting users SMTP addresses

gd6627
gd6627 asked
on
104 Views
1 Endorsement
Last Modified: 2018-10-11
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

Zaheer IqbalTechnical Assurance & Implementation
CERTIFIED EXPERT

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
CERTIFIED EXPERT
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

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
CERTIFIED EXPERT
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
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION