Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCGV ignores type data formatting and formats based off format data #235

Open
3 tasks done
windowswithoutborders opened this issue Jan 16, 2024 · 4 comments
Open
3 tasks done
Labels
bug Something isn't working Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools OCGV

Comments

@windowswithoutborders
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

When working with a PSCustomObject that has type data for the default display of its properties, OCGV seemingly ignores it.

For the following:

$myObject = [pscustomobject]@{
    PSTypeName='MyType'
    A='a'
    B='b'
    C='c'
}
Update-TypeData -TypeName 'MyType' -DefaultDisplayPropertySet A, B
$myObject | Out-ConsoleGridView

The expected display inside OCGV would be the DefaultDisplayPropertySet (A, B), but instead it is the object in its entirety. I would have to guess that is because it's formatting based off of internal formatting rules for PSCustomObject and completely disregarding the type data associated with the custom PSTypeName in the object (which is why something like Get-ChildItem works fine with OCGV).

The actual behavior is an inconvenience when working with a custom object that has a set of properties, some of which you would like to display, and some you would like to hide but keep inside the object for later processing in the pipeline. This means that
Select-Object would not work in this instance, and messing with the *-FormatData cmdlets would be overkill.

If type data cannot be accommodated, maybe OCGV could have a parameter that sets the -VisibleProperties of an object, thus allowing you to neatly display just what you want inside OCGV, while still having access to the full object in the pipeline. For now, I just ignore the excess information when I use OCGV in my scripts.

Expected behavior

# the expected object display inside OCGV

A B
- -
a b

Actual behavior

# What is actually displayed in OCGV

A B C
- - -
a b c

Error details

No response

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1


> Get-Module -ListAvailable -Name Microsoft.PowerShell.ConsoleGuiTools

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     0.7.6.0               Microsoft.PowerShell.ConsoleGuiToo… Core      {Out-ConsoleGridView, Show-ObjectTree, ocgv, sot}

Version

7.6.0

Visuals

No response

@tig tig added the bug Something isn't working label Jan 16, 2024
@tig
Copy link
Collaborator

tig commented Jan 16, 2024

Thanks for this report. I'll look into it asap.

@tig tig added Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools OCGV labels Jan 16, 2024
@windowswithoutborders
Copy link
Author

Thank you, it's much appreciated. If it's of any assistance with debugging, Out-GridView displays the object based on its type data formatting as expected--that is to say, with only the default properties (property A and property B in the example) being displayed.

> Out-GridView -InputObject $myObject -OutputMode Multiple | ForEach-Object ({$_.C})
c

@HotCakeX
Copy link

HotCakeX commented Feb 20, 2024

I just hit this problem too

I'm doing this

$Visible = [System.Management.Automation.PSPropertySet]::new(
    'DefaultDisplayPropertySet',
    $PropertiesToDisplay
)
           
foreach ($Element in $EventsToDisplay) {
    $Element | Add-Member -MemberType 'MemberSet' -Name 'PSStandardMembers' -Value $Visible
}

And Out-ConsoleGridView doesn't respect that and still shows all properties.


Out-GridView built-in cmdlet doesn't have this problem.

Using PowerShell 7.4.1 and tried on 7.5.0 beta

@tig
Copy link
Collaborator

tig commented Feb 20, 2024

I've not had a chance to look at this. Sorry about that. Will do in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Module-ConsoleGuiTools This issue is about Microsoft.PowerShell.ConsoleGuiTools OCGV
Projects
None yet
Development

No branches or pull requests

3 participants