从调用命令返回带有上下文的选择字符串结果(显示为空白)



我正在尝试使用Invoke-Command搜索多个服务器上的日志文件并返回带有上下文的结果,但我没有成功。

这是命令:

Invoke-Command -Session $session {
cd C:LogDirLog1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5 
}

这将返回一个反序列化的 MatchInfo 对象,其中大部分信息被丢弃。

如何获得类似于在本地运行选择字符串的结果?

这是在我的家庭目录的 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" 

管道slsOut-String

Invoke-Command -Session $session {
cd C:LogDirLog1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5 | Out-String
}

由于某种原因,返回的 psobject 中的自定义格式显示为空白。 这是另一种解决方法。

Invoke-Command -Session $session {
cd C:LogDirLog1
select-string -Pattern "ThingImLookingFor" -Path * -Context 1,5 | select line
}

Invoke-Command -Session $session {
cd C:LogDirLog1
select-string -Pattern "ThingImLookingFor" -Path * -Context 1,5 
} | select line, pscomputername

最新更新