2017-03-09 80 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参数一起使用。 ?? 我知道你需要先打开会话,但我相信这对于一些特殊文件更加节省。

相关问题