Paal Braathen

My feedback

  1. 16 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  14 comments  ·  PowerShell » Microsoft.PowerShell.* Modules  ·  Flag idea as inappropriate…  ·  Admin →
    Paal Braathen commented  · 

    I might agree, but I find the behavior confusing.

    Does anyone know what actually happens with an object when you "cast" it to [PSObject]?

    These objects seem equal, but somehow aren't:

    PS M:\> [PSObject] $o = @(@("Foo",1),@("Bar",2))

    PS M:\> [System.Array] $a = @(@("Foo",1),@("Bar",2))

    PS M:\> $o.GetType()

    IsPublic IsSerial Name BaseType
    -------- -------- ---- --------
    True True Object[] System.Array

    PS M:\> $a.GetType()

    IsPublic IsSerial Name BaseType
    -------- -------- ---- --------
    True True Object[] System.Array

    PS M:\> ConvertTo-Json -Compress $o
    {"value":[["Foo",1],["Bar",2]],"Count":2}

    PS M:\> ConvertTo-Json -Compress $a
    [["Foo",1],["Bar",2]]

Feedback and Knowledge Base