none
Get-Type | Sort-Object produces different objects depending on -Descending RRS feed

  • Question

  • Why does Sort-Object produce different objects when -Descending is used from Get-Type? The NoteProperty members are not the same. https://gallery.technet.microsoft.com/scriptcenter/Get-Type-Get-exported-fee19cf7

    Also, when writing to the console, the Name property does not appear unless -Descending is used. Why is that?

    C:>Get-Type | Select-Object -Property BaseType,Name | gm

       TypeName: Selected.System.RuntimeType

    Name        MemberType   Definition
    ----        ----------   ----------
    Equals      Method       bool Equals(System.Object obj)
    GetHashCode Method       int GetHashCode()
    GetType     Method       type GetType()
    ToString    Method       string ToString()
    BaseType    NoteProperty RuntimeType BaseType=System.Object
    Name        NoteProperty string Name=Registry

    C:>Get-Type | Select-Object -Property BaseType,Name | Sort-Object -Property BaseType,Name | gm

       TypeName: Selected.System.RuntimeType

    Name        MemberType   Definition
    ----        ----------   ----------
    Equals      Method       bool Equals(System.Object obj)
    GetHashCode Method       int GetHashCode()
    GetType     Method       type GetType()
    ToString    Method       string ToString()
    BaseType    NoteProperty object BaseType=null
    Name        NoteProperty string Name=_Activator

    C:>Get-Type | Select-Object -Property BaseType,Name | Sort-Object -Property BaseType,Name -Descending | gm

       TypeName: Selected.System.RuntimeType

    Name        MemberType   Definition
    ----        ----------   ----------
    Equals      Method       bool Equals(System.Object obj)
    GetHashCode Method       int GetHashCode()
    GetType     Method       type GetType()
    ToString    Method       string ToString()
    BaseType    NoteProperty RuntimeType BaseType=System.Xml.Xsl.XsltException
    Name        NoteProperty string Name=XsltCompileException


    • Moved by Bill_Stewart Friday, January 26, 2018 6:37 PM This is not support forum for gallery scripts
    Sunday, December 24, 2017 6:05 PM

All replies

  • Different objects are the first in the collection so you get different results.  The code is pretty much pointless.  What is it you are really trying to do?

    Do this:

    (Get-Type)[0]
    (Get-Type)[-1]

    Running GM on a collection gets the first item in the collection.


    \_(ツ)_/

    Monday, December 25, 2017 1:02 AM
  • When -Descending is not used, only BaseType is emitted. Why is that? How can I get the Name member to also be produced?
    Tuesday, December 26, 2017 1:09 AM