简体   繁体   中英

How to use PowerShell Where-Object to return TFS changesets that have no workitems assigned?

I have the following PowerShell command to retrieve TFS changesets with associated workitems:

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -Recursive 
  | Select ChangesetId -exp WorkItems 
  | Format-Table ChangesetId, Id, Title -Auto

However, I also need to see changesets that have no assigned workitem. I imagined I could do the following (modified as per suggestion below):

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -Recursive 
  | Select ChangesetId -exp WorkItems 
  | Where-Object {$_.WorkItems -eq $null }

However this seems to ignore my where clause and returns the same list of changesets as the first command.

Thanks

Boz

Update:

As per suggestion below, I tried:

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -Recursive 
  | Where-Object {$_.WorkItems -eq $null }

This doesn't return any rows. However swapping -eq for -ne does return rows (but not the ones I want obviously).

Select object returns only the fields you request. So you wouldn't see and object in the pipeline by the time it gets to where object if you use the where-object before select it should work.

The WorkItems field is actually a collection or workitems, so null check is wrong, but counting 0 items works:

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -Recursive 
  | Where-Object {$_.WorkItems.Count -eq 0 }

Also, the order of Where and Select is important, as 'rerun' user pointed out above, thanks.

Boz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM