我正在运行以下PowerShell,我的问题是为什么第二个命令没有返回任何结果?另外,我应该使用where
还是Where-Object
?见下面的截图。
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*')
答案 0 :(得分:0)
Where-Object
需要脚本块或比较语句(3.0+)。
在您的情况下,用大括号替换括号将起作用:
Get-Command -Module "Microsoft.TeamFoundation.PowerShell" |
Where-Object {$_.Name -like '*Tfs*'}
或者您可以使用比较声明:
Get-Command -Module "Microsoft.TeamFoundation.PowerShell" |
Where-Object -Property Name -like '*Tfs*'