Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在Powershell中从远程服务器检索文件_Powershell - Fatal编程技术网

正在Powershell中从远程服务器检索文件

正在Powershell中从远程服务器检索文件,powershell,Powershell,是否有任何方法可以调用命令,获取远程服务器上的文件内容,然后将内容写入本地计算机上的文件 希望能有这样的结果: Invoke-Command -ComputerName ###.##.###.## { $file= Get-Content C:\Windows\System32\drivers\etc\hosts } -Credential $cred $file | Out-File \\path\to\local\machine 你就快到了 $file = Invoke-Command -

是否有任何方法可以调用命令,获取远程服务器上的文件内容,然后将内容写入本地计算机上的文件

希望能有这样的结果:

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

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

为什么不将复制项与-FromSession参数一起使用??
我知道您需要先打开会话,但我认为保存一些特殊文件更方便。

如果我使用
-AsJob
标志怎么办?如何访问
Get Content
的结果,而不是
-AsJob
返回的内容?