2016-09-16 50 views
0

我從文件中讀取服務器列表:如何調用命令的結果保存到一個文件

$servidores = Get-Content "C:\ServerList.txt" 

爲我執行以下命令

foreach ($server in $servidores){ 
    Invoke-Command -ComputerName $server -ScriptBlock {Select-String -Pattern "something" -Path C:\*.txt -AllMatches} 
} 

我需要存儲的每個服務器結果在一個變量中,但找不到最好的方式來做到這一點。

回答

1

我希望你可以嘗試這個 -

$output = @() 
foreach ($server in $servidores) 
{ 
    $singleOutput = Invoke-Command -ComputerName $server -ScriptBlock {Select-String -Pattern "a" -Path C:\*.txt -AllMatches} 
    $output+= $singleOutput 
} 
$output 
+0

謝謝你 - 那工作 –

+0

乾杯!祝你今天愉快。 – Atf

相關問題