'Class with hidden property breaking for-display formatting?

Related to this interesting question from zett42, seems like object instances with hidden or private properties could be breaking the for-display formatting when piped to Get-Member as well as Select-Object *.

Hopefully someone could shed some light on this odd behavior.

class MyBool2 {
    hidden [bool] $Value
    
    MyBool2([bool] $Value) {
        $this.Value = $Value
    }

    [string] ToString() {
        return "$($this.Value)"
    }
}

$instance = [MyBool2] $true

Once the instance has been initialized, from our console:

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()
True

NOTE, this behavior is only observed in PowerShell Core. Does not seem to be the case for Windows PowerShell.

GitHub Issue #17071 has been submitted for anyone wanting to jump in.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source