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

梦想与她 提交于 2019-12-24 08:47:10

问题


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?


回答1:


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 = { $_ }}
    )


来源:https://stackoverflow.com/questions/49496237/powershell-get-mailbox-split-multi-value-grantsendonbehalfto-to-its-own-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!