-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group
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
If you define a class with only hidden properties and an overload to the ToString() method, displaying the object falls back to the ToString() method, as expected.
But a call to Get-Member on such an object, forces a full ETS refresh: the formatter now believes the type has visible members and switches to the list renderer, resulting in blank lines (since actually all members are hidden) instead of the expected ToString().
I found this issue was first noticed in issue #17071 but I just ran into it myself when coding a new class in PowerShell. It's still occurring on PowerShell 7.5.2 .
Code snippet
1. Minimalistic sample class
class CustomClass {
hidden [string] $myString
CustomClass([string] $newVal) { $this.myString = $newVal }
[string] ToString() { return $this.myString }
}
$myObject = [CustomClass]"Test"
# 1. Normal display uses ToString()
$myObject
# 2. Inspect the object
$myObject | Get-Member
# 3. Display again – blank line appears
$myObjectExpected behavior
PS /> $myObject = [CustomClass]"Test"
PS /> $myObject
Test
PS /> $myObject | Get-Member
TypeName: CustomClass
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PS /> $myObject
TestActual behavior
PS /> $myObject = [CustomClass]"Test"
PS /> $myObject
Test
PS /> $myObject | Get-Member
TypeName: CustomClass
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PS /> $myObjectError details
Environment data
PS /> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Darwin 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.…
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
No response
mklement0
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group