我从文件中读取服务器列表:
$servidores = Get-Content "C:\ServerList.txt"
为每个服务器执行以下命令
foreach ($server in $servidores){
Invoke-Command -ComputerName $server -ScriptBlock {Select-String -Pattern "something" -Path C:\*.txt -AllMatches}
}
我需要将结果存储在变量中,但无法找到最佳方法。
答案 0 :(得分:1)
我希望你能尝试一下 -
$output = @()
foreach ($server in $servidores)
{
$singleOutput = Invoke-Command -ComputerName $server -ScriptBlock {Select-String -Pattern "a" -Path C:\*.txt -AllMatches}
$output+= $singleOutput
}
$output