2017-03-09 118 views
0

有沒有什麼辦法可以調用一個獲取遠程服務器上文件內容的命令,然後將內容寫入本地機器上的文件?從Powershell中的遠程服務器中檢索文件

希望這樣的事情:

Invoke-Command -ComputerName ###.##.###.## { $file= Get-Content C:\Windows\System32\drivers\etc\hosts } -Credential $cred 
$file | Out-File \\path\to\local\machine 

回答

1

你是幾乎沒有。

$file = Invoke-Command -ComputerName ###.##.###.## { Get-Content C:\Windows\System32\drivers\etc\hosts } -Credential $cred 
$file | Out-File \\path\to\local\machine 
+0

謝謝你,工作就像一個魅力! –

+0

如果我使用'-AsJob'標誌怎麼辦?我如何訪問'Get-Content'的結果而不是'-AsJob'返回的結果? –

0

爲什麼不把copy-item和-FromSession參數一起使用。 ?? 我知道你需要先打開會話,但我相信這對於一些特殊文件更加節省。

相關問題