You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot display two or more variables successively when "Select-Object" used #12825
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.WG-Cmdletsgeneral cmdlet issues
This is because Select-Object generates objects of the same type always, and the formatter doesn't handle that well if you don't have something of a different type in between them, or use Out-Default as mentioned.
To add to Rain Sallow (/u/ta11ow) (@vexx32)'s comment: the short of it is that implicitFormat-Table formatting locks the display columns in based on the first object's properties This Stack Overflow answer explains the problem in more detail.
This has come up previously in a number of issues:
Closed as by-design: #7839 (#4552 is in part about the same problem)
Open: #7871, which proposes issuing a warning if properties are "lost".
Cases like this and the prevalence of PSCustomObject use in PS is part of why I think that the decisions made in #7839 and #4552 are missing the point. 😕
Of course we want to encourage use of similar-shaped objects in a single output stream, but I think the current behaviour is simply completely unhelpful. It does little to help you diagnose what's wrong when it does happen, and it hides information that could (and imo should) still be shown to the user.
Reacted by Michael Klement, Matthew Gray and PowerBugi
Of course we want to encourage use of similar-shaped objects in a single output stream, but I think the current behaviour is simply completely unhelpful. It does little to help you diagnose what's wrong when it does happen, and it hides information that could (and imo should) still be shown to the user.
Yeah that's true, here are the obstacles:
Getting the formatter to maybe start a new format scheme maybe continue the previous one would be a decent chunk of effort in a already complicated system.
That would require checking the properties of every single item instead of just the first of each type. For the folks already making sure the objects they emit have the same properties this would be a huge performance hit.
While I think the best practice of similar shaped objects is a good enough reason, there are also some pretty significant technical challenges.
What if we implemented a sort of hashcode-style check for property/member collections that's based on each property's name? Then the display system can just check that.
What if we implemented a sort of hashcode-style check for property/member collections that's based on each property's name? Then the display system can just check that.
That's probably more or less how 2 would be implemented. You'd still need to do that once for every object. Generating a hash code for a sequence of sequences (e.g. a collection of strings) is still pretty expensive.
What if we added an explicit command FLUSH-HOST? The formatting problem affects mainly script writers, so they would need to know when the type in the output pipeline changes, which is doable IMHO.
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.WG-Cmdletsgeneral cmdlet issues
Activity
PowerBugi commentedon May 28, 2020
The only workaround I currently have is to add "Out-String" and it work, like :
scriptingstudio commentedon May 28, 2020
or second workaround:
out-defaultvexx32 commentedon May 28, 2020
This is because Select-Object generates objects of the same type always, and the formatter doesn't handle that well if you don't have something of a different type in between them, or use Out-Default as mentioned.
mklement0 commentedon May 28, 2020
To add to Rain Sallow (/u/ta11ow) (@vexx32)'s comment: the short of it is that implicit
Format-Tableformatting locks the display columns in based on the first object's properties This Stack Overflow answer explains the problem in more detail.This has come up previously in a number of issues:
Closed as by-design:
#7839 (#4552 is in part about the same problem)
Open:
#7871, which proposes issuing a warning if properties are "lost".
vexx32 commentedon May 28, 2020
Cases like this and the prevalence of PSCustomObject use in PS is part of why I think that the decisions made in #7839 and #4552 are missing the point. 😕
Of course we want to encourage use of similar-shaped objects in a single output stream, but I think the current behaviour is simply completely unhelpful. It does little to help you diagnose what's wrong when it does happen, and it hides information that could (and imo should) still be shown to the user.
SeeminglyScience commentedon May 28, 2020
Yeah that's true, here are the obstacles:
While I think the best practice of similar shaped objects is a good enough reason, there are also some pretty significant technical challenges.
vexx32 commentedon May 28, 2020
🤔
What if we implemented a sort of hashcode-style check for property/member collections that's based on each property's name? Then the display system can just check that.
SeeminglyScience commentedon May 28, 2020
That's probably more or less how
2would be implemented. You'd still need to do that once for every object. Generating a hash code for a sequence of sequences (e.g. a collection of strings) is still pretty expensive.yecril71pl commentedon Jul 16, 2020
What if we added an explicit command
FLUSH-HOST? The formatting problem affects mainly script writers, so they would need to know when the type in the output pipeline changes, which is doable IMHO.iSazonov commentedon Jan 16, 2021
It is known problem and it is still "by-design". This does not prohibit anyone from looking for a solution if someone wants