# Help out output of data

**URL:** <https://forums.powershell.org/t/help-out-output-of-data/21889>\
**Category:** PowerShell Help\
**Created:** [March 15, 2023, 8:45pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889 "2023-03-15T20:45:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Jeffrey](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@Chris\_Jeffrey](https://forums.powershell.org/u/Chris_Jeffrey)\
**Post date:** [March 15, 2023, 8:45pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889/1 "2023-03-15T20:45:24Z")

</div>

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.  
Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [March 15, 2023, 8:54pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889/2 "2023-03-15T20:54:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 15, 2023, 9:12pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889/3 "2023-03-15T21:12:08Z")

</div>

Chris,  
Welcome to the forum. 👋🏼

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

```auto
Get-Mailbox | 
    Select-Object DisplayName, 
        @{
            Name = 'EmailAddresses';
            Expression = { $_.EmailAddresses | Where-Object { $_ -LIKE 'SMTP:*' } } 
        } |
        ForEach-Object {
            foreach ($Email in $_.EmailAddresses) {
                [PSCustomObject]@{
                    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 PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

---

<div class="post-metadata">

**Author:** ![Chris\_Jeffrey](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@Chris\_Jeffrey](https://forums.powershell.org/u/Chris_Jeffrey)\
**Post date:** [March 16, 2023, 2:00pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889/4 "2023-03-16T14:00:15Z")

</div>

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.  
Cheers

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:15pm UTC](https://forums.powershell.org/t/help-out-output-of-data/21889/5 "2024-05-16T20:15:02Z")

</div>

Closed on May 16, 2024, 8:15pm UTC


