从Invoke-Command返回带有上下文的选择字符串结果(显示为空白)

问题描述 投票:0回答:2

我正在尝试使用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" 
powershell powershell-remoting select-string
2个回答
1
投票

sls设置为Out-String

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

0
投票

由于某些原因,返回的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
© www.soinside.com 2019 - 2024. All rights reserved.