powershell - Why doesn't "where" work as I would expect here to select certain results? -


i'm running following powershell , questions why doesn't second command return results? also, should using where or where-object? see screenshot below.

write-host "this displays all..." -foregroundcolor green get-command -module "microsoft.teamfoundation.powershell"  write-host "this displays nothing..." -foregroundcolor yellow get-command -module "microsoft.teamfoundation.powershell" | where-object ($_.name -like '*tfs*') 

enter image description here

where-object requires either scriptblock or comparison statement (3.0+).

in case, replacing parenthesis curly brace work:

get-command -module "microsoft.teamfoundation.powershell" |     where-object {$_.name -like '*tfs*'} 

or use comparison statement:

get-command -module "microsoft.teamfoundation.powershell" |     where-object -property name -like '*tfs*' 

Comments