【发布时间】:2021-01-31 04:21:15
【问题描述】:
我想在没有 WINRM 的情况下将文件从本地服务器复制到远程服务器。远程服务器已获得凭据,并且不在本地网络或本地服务器的本地域中。 请问有解决办法吗?
I have this error:
MethodInvocationException: D:\powershell\ip.ps1:23:1
Line |
23 | $WebClient.DownloadFile($Source, $Dest)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
Here is my code:
$Source = "C:\test10\test10.txt"
$Dest = "\\public_ipadress_server\C:\test11\test10.txt"
$Username = "administrator"
$Password= convertto-securestring -AsPlainText -Force -String password
$MyIP = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
$MyIP | Out-File $Source
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
$WebClient.DownloadFile($Source, $Dest)
【问题讨论】:
-
我无法使用 WINRM,因为在我的服务器和远程服务器中配置太难了。我已经阅读了这个链接,所以我尝试了另一种解决方案。 docs.microsoft.com/fr-fr/powershell/module/…
标签: powershell