Repository navigation
Closed
Labels
Issue-BugIssue has been identified as a bug in the productNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Object instances with hidden or private properties could be breaking the for-display formatting when piped to Get-Member as well as Select-Object *.
class MyBool2 {
hidden [bool] $Value
MyBool2([bool] $Value) {
$this.Value = $Value
}
[string] ToString() {
return "$($this.Value)"
}
}Expected behavior
PS /> $instance = [MyBool2] $true
PS /> $instance
True
PS /> $instance | Get-Member
TypeName: MyBool2
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PS /> $instance
True
PS /> $instance.ToString()
TrueActual behavior
PS /> $instance = [MyBool2] $true
PS /> $instance
True
PS /> $instance | Get-Member
TypeName: MyBool2
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PS /> $instance
PS /> $instance.ToString()
TrueError details
No errors.
Environment data
Name Value
---- -----
PSVersion 7.2.2
PSEdition Core
GitCommitId 7.2.2
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
No response
Reacted by Patrick Meinecke, zett42, Michael Klement and FireInWinter
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues
Activity
zett42 commentedon Mar 27, 2022
It might be hard to see, the output of
$instanceafter the call toGet-Memberonly consists of a newline instead of the expectedTrue.kasini3000 commentedon Mar 30, 2022
Seems this a vague question,
Actual behavior same with Expected behavior
zett42 commentedon Mar 30, 2022
It isn't. Compare the output of
$instanceafter call toGet-Member.Expected:
Actual:
Note that there is just an empty line in the actual output of
$instance.When inserting a
[Console]::WriteLine()call in theToString()method, we can observe thatToString()isn't even called anymore. It appears thatGet-Membercorrupts the object in a way that its default output no longer works.The corruption only occurs for the object that gets passed to
Get-Member. When creating a new instance ofMyBool2afterwards, it's output is correct again.More observations:
Conclusion: Any output that involves PowerShell's formatting system appears to be broken.
kasini3000 commentedon Mar 31, 2022
I understood the problem from your explain, and found inconsistent behavior.
ps 5.1,ps 6.2.7:
ps 7.3.3
microsoft-github-policy-service commentedon Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 22, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.