简体   繁体   中英

Powershell, split listing Get-Mailbox EmailAddresses

This is my Powershell command:

Get-Mailbox -Identity <Display Name> -ResultSize Unlimited |
   List DisplayName, PrimarySmtpAddress, EmailAddresses | 
   Format-List -Wrap  PrimarySmtpAddress, EmailAddresses

But when there are more then 1 EmailAddresses for a user, it keeps everything together.

I Would like to have the EmailAddresses split after each SPACE so it looks like this:

在此处输入图片说明

Get-MailBox -ResultSize Unlimited | Select DisplayName, PrimarySmtpAddress, `
 @{Name='Email';Expression={ $_.EmailAddresses.SmtpAddress -join "`n" }} |
Format-Table -Wrap

Should do it.


The EmailAddresses property contains objects with many properties, there is no space to split on, because it's not a single string. So you can't use -wrap to change it, because it's not a string being wrapped. This answer uses a calculated property to turn all the email addresses into a string, which can then be -wrap ped.


-ResultSize Unlimited is for returning lots of results, -Identity <displayname> is for returning a single result, using both together doesn't make much sense.

List is an alias for Format-List , so you're trying to pipe the output of Format-List back into Format-List, this is never going to do anything useful.

Format-List output is a property list, but you describe your desired output as a table, it's the wrong command to give that kind of output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM