Windows Vista Forums

Get-Member repeats members for identical types - bug?

  1. #1


    Alex K. Angelopoulos [MVP] Guest

    Get-Member repeats members for identical types - bug?

    I was trying a few esoteric methods for collecting information, and noticed
    an oddity when I was trying to find properties of repeated String[]
    objects: Get-Member would repeat identical members over and over, under a
    single System.String typename. Example below. Anyone know the reason for
    this? My hunch is it is probably a bug and is probably due to repeated
    hard-typed arrays:

    PS> Get-ChildItem hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    | ForEach-Object { Get-Member -InputObject $_.GetValueNames() } |
    Select-Object -First 200


    TypeName: System.String[]

    Name MemberType Definition
    ---- ---------- ----------
    Count AliasProperty Count = Length
    Address Method System.String& Address(Int32 )
    ....
    Rank Property System.Int32 Rank {get;}
    SyncRoot Property System.Object SyncRoot {get;}
    Count AliasProperty Count = Length
    Address Method System.String& Address(Int32 )
    ....
    Rank Property System.Int32 Rank {get;}
    SyncRoot Property System.Object SyncRoot {get;}
    Count AliasProperty Count = Length
    Address Method System.String& Address(Int32 )
    ....
    Rank Property System.Int32 Rank {get;}
    SyncRoot Property System.Object SyncRoot {get;}
    Count AliasProperty Count = Length
    Address Method System.String& Address(Int32 )
    ....





      My System SpecsSystem Spec

  2. #2


    dreeschkind Guest

    RE: Get-Member repeats members for identical types - bug?

    I'm not 100% sure, but I think this is what's going on:

    Get-Member usually gives you member information only once for every type you
    pipe into it (or hand over to it using -InputObject).
    What you are doing is actually calling Get-Member several times
    (Foreach-Object) and with one single object each time. So every time
    Get-Member is invoked it returns type information for one single object
    (String[]).
    After that the all generated
    "Microsoft.PowerShell.Commands.MemberDefinition"-objects get automagically
    piped into PoSh's magic formating cmdlets, which recognize that all have
    actually the same type and thus present the header
    "Name MemberType Definition" only once for all members.

    I hope that makes sense for you.
    Please someone correct my if I'm wrong.

    --
    greetings
    dreeschkind


    "Alex K. Angelopoulos [MVP]" wrote:

    > I was trying a few esoteric methods for collecting information, and noticed
    > an oddity when I was trying to find properties of repeated String[]
    > objects: Get-Member would repeat identical members over and over, under a
    > single System.String typename. Example below. Anyone know the reason for
    > this? My hunch is it is probably a bug and is probably due to repeated
    > hard-typed arrays:
    >
    > PS> Get-ChildItem hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    > | ForEach-Object { Get-Member -InputObject $_.GetValueNames() } |
    > Select-Object -First 200
    >
    >
    > TypeName: System.String[]
    >
    > Name MemberType Definition
    > ---- ---------- ----------
    > Count AliasProperty Count = Length
    > Address Method System.String& Address(Int32 )
    > ....
    > Rank Property System.Int32 Rank {get;}
    > SyncRoot Property System.Object SyncRoot {get;}
    > Count AliasProperty Count = Length
    > Address Method System.String& Address(Int32 )
    > ....
    > Rank Property System.Int32 Rank {get;}
    > SyncRoot Property System.Object SyncRoot {get;}
    > Count AliasProperty Count = Length
    > Address Method System.String& Address(Int32 )
    > ....
    > Rank Property System.Int32 Rank {get;}
    > SyncRoot Property System.Object SyncRoot {get;}
    > Count AliasProperty Count = Length
    > Address Method System.String& Address(Int32 )
    > ....
    >
    >
    >


      My System SpecsSystem Spec

  3. #3


    dreeschkind Guest

    RE: Get-Member repeats members for identical types - bug?

    This is an example on how to avoid this phenomenon:

    Get-ChildItem hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
    Select-Object -First 200 | ForEach-Object {$_.GetValueNames()} | Get-Member

    --
    greetings
    dreeschkind


    "dreeschkind" wrote:

    > I'm not 100% sure, but I think this is what's going on:
    >
    > Get-Member usually gives you member information only once for every type you
    > pipe into it (or hand over to it using -InputObject).
    > What you are doing is actually calling Get-Member several times
    > (Foreach-Object) and with one single object each time. So every time
    > Get-Member is invoked it returns type information for one single object
    > (String[]).
    > After that the all generated
    > "Microsoft.PowerShell.Commands.MemberDefinition"-objects get automagically
    > piped into PoSh's magic formating cmdlets, which recognize that all have
    > actually the same type and thus present the header
    > "Name MemberType Definition" only once for all members.
    >
    > I hope that makes sense for you.
    > Please someone correct my if I'm wrong.
    >
    > --
    > greetings
    > dreeschkind
    >
    >
    > "Alex K. Angelopoulos [MVP]" wrote:
    >
    > > I was trying a few esoteric methods for collecting information, and noticed
    > > an oddity when I was trying to find properties of repeated String[]
    > > objects: Get-Member would repeat identical members over and over, under a
    > > single System.String typename. Example below. Anyone know the reason for
    > > this? My hunch is it is probably a bug and is probably due to repeated
    > > hard-typed arrays:
    > >
    > > PS> Get-ChildItem hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    > > | ForEach-Object { Get-Member -InputObject $_.GetValueNames() } |
    > > Select-Object -First 200
    > >
    > >
    > > TypeName: System.String[]
    > >
    > > Name MemberType Definition
    > > ---- ---------- ----------
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > >
    > >
    > >


      My System SpecsSystem Spec

  4. #4


    dreeschkind Guest

    RE: Get-Member repeats members for identical types - bug?

    BTW, my example did not return members of String[] as you might have intended
    to see, so here is a simplified version of your example that does this:

    #members of [String[]]
    [String]$a = "foo"
    [String[]]$b = $a,$a
    $b | % {gm -i $b}

    This would be a more simplified example on the 'bug' your were seeing:

    #members of [String]
    "foo","bar" | % {$_ | gm}


    --
    greetings
    dreeschkind

    "dreeschkind" wrote:

    > I'm not 100% sure, but I think this is what's going on:
    >
    > Get-Member usually gives you member information only once for every type you
    > pipe into it (or hand over to it using -InputObject).
    > What you are doing is actually calling Get-Member several times
    > (Foreach-Object) and with one single object each time. So every time
    > Get-Member is invoked it returns type information for one single object
    > (String[]).
    > After that the all generated
    > "Microsoft.PowerShell.Commands.MemberDefinition"-objects get automagically
    > piped into PoSh's magic formating cmdlets, which recognize that all have
    > actually the same type and thus present the header
    > "Name MemberType Definition" only once for all members.
    >
    > I hope that makes sense for you.
    > Please someone correct my if I'm wrong.
    >
    > --
    > greetings
    > dreeschkind
    >
    >
    > "Alex K. Angelopoulos [MVP]" wrote:
    >
    > > I was trying a few esoteric methods for collecting information, and noticed
    > > an oddity when I was trying to find properties of repeated String[]
    > > objects: Get-Member would repeat identical members over and over, under a
    > > single System.String typename. Example below. Anyone know the reason for
    > > this? My hunch is it is probably a bug and is probably due to repeated
    > > hard-typed arrays:
    > >
    > > PS> Get-ChildItem hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    > > | ForEach-Object { Get-Member -InputObject $_.GetValueNames() } |
    > > Select-Object -First 200
    > >
    > >
    > > TypeName: System.String[]
    > >
    > > Name MemberType Definition
    > > ---- ---------- ----------
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > > Rank Property System.Int32 Rank {get;}
    > > SyncRoot Property System.Object SyncRoot {get;}
    > > Count AliasProperty Count = Length
    > > Address Method System.String& Address(Int32 )
    > > ....
    > >
    > >
    > >


      My System SpecsSystem Spec

Get-Member repeats members for identical types - bug?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove members of the group. Members are from different domains pawp PowerShell 0 09 Jun 2009
Unexpected error $instance.psobject.members.Add($member) RickB PowerShell 2 10 Apr 2008
types.custom.ps1xml for custom members hasten PowerShell 0 25 Feb 2008
email repeats Gary Vista mail 2 26 Aug 2007
Converting proxy generated types to original types Daniel Indigo 1 06 Jan 2007