简体   繁体   中英

Is there a way to use more elements than display in an Out-GridView array

I am trying to allow a user to multiselect from a list of results returned from a command, using Out-GridView .

However, I seem to have to ask for the elements I need later on AND display them in the Out-GridView . But it gets chaotic in there!

Can I show less of them in the Out-GridView ?

I have tried pulling in the command into another variable and then selecting the elements I want to show in the grid view, but that has the same result, or I am not doing it right.

For example:

$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

Returns:

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...

Although $delboxes will return everything I asked for in the Get-Mailbox | Select-Object part, there is too much to display on the screen when there are many EmailAddresses. So the Name and Alias get shrunk to a few characters

So I want just a few of the elements to show in the Out-GridView, but to be able to use them all later on in my script.

If I only put this in the script

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

I am unable to use the element ArchiveName without requerying the Get-Mailbox command

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

PS> $delboxes.ArchiveName | ft

There is nothing :-(

And using default display set gives me an unusable Out-GridView and not the elements I require either

$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

To have the Out-Gridview with only reduced properties and nevertheless afterwards have access to all properties,
you might save the selection and use Compare-Object with -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

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