Select-Object on nested collections

powershell, tfs

Solution

Your can use `-ExpandProperty` parameter of `Select-Object` cmdlet. It will expand collection and add selected properties from parent object to child objects:

$changesets | Select-Object ChangeSetId, Owner, Comment,
    @{Name="Changes"; Expression={ $_.Changes | Select-Object ChangeType, ServerItem }} |
Select-Object -Property * -ExcludeProperty Changes -ExpandProperty Changes

Problem

I'm writing a Powershell cmdlet to list changesets from TFS. I successfully query TFS and get a collection of changesets but want to return simplified objects that contain only a few properties. I can do that using `Select-Object` like this... ``` $changesets | Select-Object ChangeSetId, Owner, Comment ``` The last property I would like to add is the `Changes` property which is an array of changes. I would like to simplify those objects as well. I'm trying this but it doesn't return what I want... ``` $changesets | Select-Object ` ChangeSetId, Owner, Comment, @{Name="Changes"; Expression={ $_.Changes | Select-Object ChangeType, ServerItem }} ``` Is there a way to handle nested collections with `Select-Object`?

Original source