Using powershell and get-mailbox command to display raw smtp addresses

Posted on 2009-05-02
Last Modified: 2012-05-06
Hi, I'm trying to pass the windowsemailaddress field from the get-mailbox command using the Exchange 2007 Powershell to another part of a script.

Unfortunately, when I use something like:

Get-Mailbox | select WindowsEmailAddress
Get-Mailbox | fl WindowsEmailAddress

it passes the column heading and some other weird characters to the variable. The actual code I'm using is included.

How can I pass raw email addresses to the next part of the script? ie. like they were from a text file and each smtp address was on a new line, no spaces or carrage returns etc.

[void][Reflection.Assembly]::LoadFile("E:\Exchange scripts\ewsutil\EWSUtil.dll")

$AllAddresses = Get-Mailbox | select WindowsEmailAddress

foreach($userEM in $AllAddresses)


$setPPTo = "0"

$casUrl = "https://fsatg10ech001/ews/exchange.asmx"

$mbMailboxEmail= $userEM

$ewc = new-object EWSUtil.EWSConnection("migrator2@# removed by modernmatt #",$true, $null, $null, $null,$casUrl)


$fldarry = new-object EWSUtil.EWS.BaseFolderIdType[] 1

$dTypeFld = new-object EWSUtil.EWS.DistinguishedFolderIdType

$dTypeFld.Id = [EWSUtil.EWS.DistinguishedFolderIdNameType]::msgfolderroot

$mbMailbox = new-object EWSUtil.EWS.EmailAddressType

$mbMailbox.EmailAddress = $mbMailboxEmail

$dTypeFld.Mailbox = $mbMailbox

$fldarry[0] = $dTypeFld


write $mbMailbox

Open in new window

Question by:Al230762
    LVL 4

    Accepted Solution

    try this:
    $AllAddresses = Get-Mailbox | %{ $_.WindowsEmailAddress.ToString() }

    Open in new window


    Author Closing Comment

    Dude that's awesome, thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    inactive users 13 30
    exchange, scripts 3 33
    Exchange Search Slow 17 33
    Upgrading Exchange 2007 SP1 to SP3 5 6
    Use email signature images to promote corporate certifications and industry awards.
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now