When did Select-Object creates ne PSCustom Objects

This topic contains 9 replies, has 4 voices, and was last updated by  PowerPete 5 years, 2 months ago.

  • Author
  • #4717



    I thougt every time I strip down some Properties from an object, Select-Object will create a new PSCustom Object!
    But this lines ar not new PSCustom Objects!
    Get-Item C:\Windows\explorer.exe | Select-Object Fullname,length
    Get-Item C:\Windows\explorer.exe | Select-Object Fullname,@{Name="Size";Expression={$_.length / 1mb}}

    Is there any rule when Select-Object is creating new PSCustom Objects from an given Object?

  • #4732

    Art Beane

     Save the Get-Item call into a variable and you will see that it really is a PSCustomObject.

    $File = Get-Item C:\Windows\explorer.exe | Select-Object Fullname,@{Name=”Size”;Expression={$_.length / 1mb}} 
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     False    PSCustomObject                           System.Object
  • #4736


    Hi Art !

    Thank you for pointing me to that!
    Even i have missed that Get-Member is reporting  Selected.System.IO.FileInfo

    Is there a rule or explanation when Select-Object is creating new Objects and when not ?

  • #4753

    Art Beane

    According to Get-Help Select-Object -Full, the cmdlet output is always:


    The output type is the type of the objects that the cmdlet emits.

    • System.Management.Automation.PSObject


  • #4772


    The documentation is not correct !
    If you use the -First -last and -Unique Parmeters the Objects are left original.
    I think the rule is:

    Whenever you strip down Properties an PScustom Object is generated!?

  • #4774

    Art Beane

    OK. It looks like you get a PSCustomObject if you specify a Property name (without -ExpandProperty, of course); otherwise it looks like the orginal object is passed through.


    (Get-QADGroup -SizeLimit 2 | Select -First 1).GetType() returns ArsGroupObject


    (Get-QADGroup -SizeLimit 2 | Select DN -First 1).GetType returns PSCustomObject

  • #4812

    Don Jones

    v2 produced a PSCustomObject. v3 produces a Selected.x.x.x object. That's in part so that the formatting system can still differentiate and provide some default formatting views, and so that the ETS can provide some type extensions. It's technically still a PSCustomObject underneath.

    But, overall, what you're dealing with is a concept call immutability. For example, a System.Diagnostics.Process ALWAYS has certain properties. Take one away, and it's no longer that object, by definition. It's like if you have a car, and I chopped off the front part. It's no longer a car, it's a wreck. So when you select anything other than -Property *, what Select-Object produces isn't the original object anymore, and so you see the TypeName change.

  • #4814

    Rob Campbell

    So when you select anything other than -Property *, what Select-Object produces isn’t the original object anymore, and so you see the TypeName change.

    Actually -Property * will get you a custom object too. It looks like the original object, but all the methods are gone.

  • #4815

    Don Jones

    Yeah, true dat. Anything other than the original ain't the original anymore ;). Like Levi's.

  • #4860


    So I like to say a big THANKS to you all for clarification. (Especially Don)
    Very hard stuff!

You must be logged in to reply to this topic.