简体   繁体   中英

Powershell: Get-Mailbox, split multi-value GrantSendOnBehalfTo to its' own line

I'm trying to run a report on users with 'Send on Behalf Of' rights to mailboxes. The results are fine if there's only a single account, but when there're multiples, the values are joined into a single string with default delimiter being spaces. Even when I use split with line-feed as delimiter, it's still treated as a single string separated by line-feed. Here's my current code:

get-mailbox "Sales Dept" | select identity,displayname,@{l='SendOnBehalfOf';e={$_.GrantSendOnBehalfTo -join "`n"}}

Whether I use split or join, I keep getting variations of this ouput:

Identity            Displayname         SendOnBehalfOf
domain\Sales Dept   Sales Dept          User1
                                        User2
                                        User3
                                        User4

But what I need is for each User be on their own line like this:

Identity            Displayname         SendOnBehalfOf
domain\Sales Dept   Sales Dept          User1
domain\Sales Dept   Sales Dept          User2
domain\Sales Dept   Sales Dept          User3
domain\Sales Dept   Sales Dept          User4

How do I get that?

Since your SendOnBehalfOf property has the most entries, it is the one you want to iterate over:

#Requires -Version 4
Get-MailBox 'Sales Dept' -PipelineVariable 'Sales' |
    ForEach-Object -MemberName 'GrantSendOnBehalfTo' |
    Select-Object -Property @(
        @{N = 'Identity';       E = { $Sales.Identity }}
        @{N = 'DisplayName';    E = { $Sales.DisplayName }}
        @{N = 'SendOnBehalfOf'; E = { $_ }}
    )

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