2016-04-11 18 views

回答

2
Select-String "succeeded" pol_inst.log | ForEach-Object Line 

或者它的命令行调用:

@powershell -command Select-String "succeeded" pol_inst.log ^| ForEach-Object Line 
1

发生这种情况是因为Select-String会返回一个MatchInfo对象的集合。除了结果之外,这些内容还包含很多内容。

简单的解决方法是使用.Line财产像这样,

select-string -path c:\myFile -pattern "myPattern" | % { $_.line } 
1

展开MatchInfo对象的Line属性,Select-String生产:

Select-String ... | Select-Object -Expand Line 
相关问题