有没有一种方法可以使用比在Out-GridView数组中显示更多的元素

时间:2019-03-27 12:46:33

标签: powershell

我正在尝试允许用户使用Out-GridView从命令返回的结果列表中进行多选。

但是,我似乎不得不在以后询问我需要的元素并将其显示在Out-GridView中。但是里面变得混乱了!

我可以在Out-GridView中显示更少的内容吗?

我尝试将命令拖入另一个变量,然后选择要在网格视图中显示的元素,但是结果相同,或者我做错了。

例如:

$Global:delboxes = Get-Mailbox -SoftDeletedMailbox | Select-Object Name,Alias,PrimarySmtpAddress,WhenSoftDeleted,ArchiveName,guid,Emailaddresses | Sort-Object -property Name | Out-GridView -Title "Please select mailbox(es)" -PassThru

返回:

PS> $delboxes | ft
Name            Alias           PrimarySmtpAddress                  WhenSoftDeleted     ArchiveName Guid                                 EmailAddresses
----            -----           ------------------                  ---------------     ----------- ----                                 -------------- 
person1         person.one      person.one@mycompany.com            25/09/2016 20:53:56 {archive}   d25cb74b-46cf-4582-9c32-6c146f59f013 {X500:/o=mycompany/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/...
person2         person.two      person.two@mycompany.com            25/09/2016 20:53:56 {}          1670a21e-a00b-461e-ae84-2ff646e2a434 {SMTP:person.two@mycompany.com, smtp:person.2@mycompany, X500:/o=mycompany/ou=Exchan...

尽管$ delboxes将返回我在Get-Mailbox中要求的所有内容|选择对象部分,当有许多EmailAddress时,屏幕上显示太多。因此,名称和别名缩小为几个字符

所以我只希望其中一些元素显示在Out-GridView中,但以后可以在我的脚本中使用它们。

如果我只将其放在脚本中

$Global:delboxes = Get-Mailbox -SoftDeletedMailbox | Select-Object Name,Alias | Sort-Object -property Name | Out-GridView -Title "Please select mailbox(es)" -PassThru

如果不重新查询Get-Mailbox命令,我将无法使用ArchiveName元素

PS> $delboxes | ft
Name            Alias
----            -----
person1         person.one
person2         person.two

PS> $delboxes.ArchiveName | ft

没有任何东西:-(

使用默认显示集会给我一个无法使用的Out-GridView,而不是我需要的元素

$Global:delboxes = Get-Mailbox -SoftDeletedMailbox | Sort-Object -property WhenSoftDeleted | Out-GridView -Title "Please select mailbox(es)" -PassThru

PS> $delboxes | ft
RunspaceId                           Database           MailboxProvisioningConstraint IsMonitoringMailbox MailboxRegion MailboxRegionLastUpdateTime MessageRecallProcessingEnabled MessageCopyForSentAsEnabled MessageCopyForSendOnBehalfEnabled
----------                           --------           ----------------------------- ------------------- ------------- --------------------------- ------------------------------ --------------------------- ------
20edeed1-036f-4832-8463-486827c61405 EURP195DG024-db030                                             False                                                                     True                       False  False
20edeed1-036f-4832-8463-486827c61405 EURP195DG013-db099                                             False                                                                     True                       False  False
20edeed1-036f-4832-8463-486827c61405 EURP195DG007-db072                                             False                                                                     True                       False  False

1 个答案:

答案 0 :(得分:0)

要使Out-Gridview仅具有减少的属性,但此后仍可以访问所有属性,
您可以保存选择并将Compare-Object与-IncludeEqual -ExcludeDifferent

一起使用
## Q:\Test\2019\03\27\SO_55377562.ps1
$Global:delboxes = Get-Mailbox -SoftDeletedMailbox | 
    Select-Object Name,Alias,PrimarySmtpAddress,WhenSoftDeleted,ArchiveName,guid,Emailaddresses | 
    Sort-Object -Property Name 

$Selection = $delboxes | Select-Object Name,Alias | 
    Out-GridView -Title "Please select mailbox(es)" -PassThru

$SelectedDelboxes = Compare-Object -Ref $delboxes -Diff $Selection -Property Name,Alias `
               -IncludeEqual -ExcludeDifferent -PassThru |
    Select-Object * -Exclude SideIndicator