Help out output of data

I’m trying to get all alias from our exchange server. I’m using the command :
Get-Mailbox | Select-Object DisplayName,@{Name=”EmailAddresses”;Expression={$.EmailAddresses |Where-Object {$ -LIKE “SMTP:*”}}} | Sort

when it output the display i get the displayname, and emailaddresses but the emailaddresses are in sring format.
I’m trying to figure out how to split the address and output them in this form:
Displayname emailaddresses
Jon smith jons@test .com
jon.smith@test .com
jsmith@test .com

But instead it displays all the emailaddresses in a string together. I want them seperated. I tried putting into a custom object and such but I had no luck.

Well emailaddresses is an array, so when you try and cram that into a single property it gets concatenated together. If your goal is a csv or something and you want to emails on separate rows you might want to loop through each mailbox and for the extra emails just have a pscustom objects with empty properties save for the email.

Then export to csv and it should be formatted like so

DisplayName_______ Email 1
__________________Email 2

Welcome to the forum. :wave:t3:

Like Justin already mentioned you will need a loop to separate the individual email addresses. Something like this should work:

Get-Mailbox | 
    Select-Object DisplayName, 
            Name       = 'EmailAddresses';
            Expression = { $_.EmailAddresses | Where-Object { $_ -LIKE 'SMTP:*' } } 
        } |
        ForEach-Object {
            foreach ($Email in $_.EmailAddresses) {
                    DisplayName  = $_.DisplayName
                    EmailAddress = $Email.EmailAddresses

And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in 1 <---- Click :point_up_2:t4: :wink:

Thanks so much for leading me in the right direction. My only change that I needed to make to the above script was in the custom object section. Just needed emailaddress = $Email
I appreciate the quick response and help guys and thanks for the tip on adding code into the forum.