Return Select - 具有来自 Invoke-Command 的上下文的字符串结果(显示为空白)
Return Select-String results with context from Invoke-Command (appear blank)
我正在尝试使用 Invoke-Command 搜索多个服务器上的日志文件,return 使用上下文搜索结果,但没有成功。
这是命令:
Invoke-Command -Session $session {
cd C:\LogDir\Log1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5
}
这 return 是一个反序列化的 MatchInfo 对象,其中大部分信息已删除。
如何在本地获得类似于 运行 Select-String 的结果?
这是 运行 sls 在我的主目录中的 svg 上的结果,示例具有相同的上下文设置:
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
我正在尝试使用 Invoke-Command 搜索多个服务器上的日志文件,return 使用上下文搜索结果,但没有成功。
这是命令:
Invoke-Command -Session $session {
cd C:\LogDir\Log1
sls -Pattern "ThingImLookingFor" -Path * -Context 1,5
}
这 return 是一个反序列化的 MatchInfo 对象,其中大部分信息已删除。
如何在本地获得类似于 运行 Select-String 的结果?
这是 运行 sls 在我的主目录中的 svg 上的结果,示例具有相同的上下文设置:
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