Q:

How to export value output without '@{}' after string replacement?

I'm trying to export forward list from Exchange 365 and remove "smtp:" string from output.
Here is PS code for Exchange 365 forwards list:
$forwards = Get-Mailbox –ResultSize Unlimited |
            where {($_.ForwardingSmtpAddress –ne $null)} |
            select identity, *forward*
$result = $forwards -replace "smtp:",""
$result

My $forwards value has format:

PS> $forwards
Identity      DeliverToMailboxAndForward ForwardingAddress ForwardingSmtpAddress
--------      -------------------------- ----------------- ---------------------
name.surname1                       True                   smtp:name.surname1@domain.com
name.surname2                       True                   smtp:name.surname2@domain.com
name.surname3                       True                   smtp:name.surname3@domain.com

I managed to remove that smtp: text with command:
$result = $forwards -replace "smtp:",""

But I get such ugly output for that variable:

PS> $result
@{Identity=name.surname1; DeliverToMailboxAndForward=True; ForwardingAddress=; ForwardingSmtpAddress=name.surname1@domain.com}
@{Identity=name.surname2; DeliverToMailboxAndForward=True; ForwardingAddress=; ForwardingSmtpAddress=name.surname2@domain.com}
@{Identity=name.surname3; DeliverToMailboxAndForward=True; ForwardingAddress=; ForwardingSmtpAddress=name.surname3@domain.com}

How to get rid of that @{} and present it right way as it was in $forwards variable? Maybe there is better way to remove smtp: from first value $forwards?

A:

You should also be able to use calculated properties:
$forwards = Get-Mailbox –resultSize unlimited |
            where { $_.ForwardingSmtpAddress –ne $null } |
            select @{Name="Identity";Expression={$_.Identity}},
                DeliverToMailboxAndForward, ForwardingAddress,
                @{Name="ForwardingSmtpAddress";Expression={$_.ForwardingSmtpAddress -replace "smtp:",""}}

I don't have the means to test this right now, though.

A:

Instead of creating a new variable it might be easier to modify the existing objects in your array. You need to do the replacement on each ForwardingSmtpAddress property:
$forwards | Foreach-Object {
    $_.ForwardingSmtpAddress = $_.ForwardingSmtpAddress -replace "smtp:", ""
}

After this, just echoing $forwards to the screen should show you the updated values.

