我正在尝试使用Invoke-Command在多台服务器上搜索日志文件,并通过上下文返回结果,但是我没有成功。
这是命令:
Invoke-Command -Session $session {
cd C:\LogDir\Log1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5
}
这将返回已删除序列号的MatchInfo对象,其中删除了大部分信息。
如何获得类似于在本地运行Select-String的结果?
这是在我的主目录中的svg上以相同的上下文设置运行sls的结果,例如:
horizontalBlock.svg:30: id="base"
> horizontalBlock.svg:31: pagecolor="#ffffff"
horizontalBlock.svg:32: bordercolor="#666666"
horizontalBlock.svg:33: borderopacity="1.0"
horizontalBlock.svg:34: inkscape:pageopacity="0.0"
horizontalBlock.svg:35: inkscape:pageshadow="2"
horizontalBlock.svg:36: inkscape:zoom="1.3289991"
将sls
设置为Out-String
:
Invoke-Command -Session $session {
cd C:\LogDir\Log1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5 | Out-String
}
由于某些原因,返回的psobject的自定义格式显示为空白。这是另一个解决方法。
Invoke-Command -Session $session {
cd C:\LogDir\Log1
select-string -Pattern "ThingImLookingFor" -Path * -Context 1,5 | select line
}
或
Invoke-Command -Session $session {
cd C:\LogDir\Log1
select-string -Pattern "ThingImLookingFor" -Path * -Context 1,5
} | select line, pscomputername