将文件发送到远程文件夹powershell

将文件发送到远程文件夹powershell,powershell,Powershell,这是我不需要密码就可以复制的东西,因为我想安排这个脚本 $Source = "d:\test\myZipFile.zip" $Dest = "\\REMOTE_ip\D$\test" $Username = "Administrator" $Password = ConvertTo-SecureString "PasswordOFRemotePC" -AsPlainText -Fo

这是我不需要密码就可以复制的东西,因为我想安排这个脚本

    $Source = "d:\test\myZipFile.zip"
    $Dest   = "\\REMOTE_ip\D$\test"
    $Username = "Administrator"
    $Password = ConvertTo-SecureString "PasswordOFRemotePC" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
    
    New-PSDrive -Name J -PSProvider FileSystem -Root $Dest -Credential $mycreds -Persist
    Copy-Item -Path $Source -Destination "d:\test\myZipFile1.zip"
但它给了我错误

New PSDrive:网络资源类型在D:\test\copy处不正确。ps1:7字符:1

  • 新的PSDrive-名称J-PSProvider文件系统-根$Dest-凭证$m

从你问题的标题来看,我认为你做得过火了

在计划任务中,决定哪个用户帐户应运行脚本。该用户应具有对计算机本地
D:\Test
文件夹的读取权限,并且必须具有对远程路径
\\remote\u ip\D$\Test
的写入/修改权限。 您可以设置任务,以便特定用户甚至不必登录

要运行的可执行文件是PowerShell.exe,参数是
-File
(为此,运行任务的用户必须对脚本文件的位置具有读取和执行权限)

然后,脚本本身可以简单到:

$Source = "d:\test\myZipFile.zip"
$Dest   = "\\REMOTE_ip\D$\test"

Copy-Item -Path $Source -Destination $Dest -Force

复制项cmdlet上的源和目标相同。只需使用
-Destination$Dest
,并确保运行计划任务的用户在那里具有写入权限,并且对源具有读取权限。不需要新的PSDrive cmdlet。错误出现在最后一部分“d:\test\myZipFile1.zip”,我必须使用映射驱动器“J:\myZipFile1.zip”确定,但仍然。。当您拥有要将文件复制到的完全限定UNC名称时,为什么需要映射?再次确保运行计划任务的用户可以访问源和源destination@Theo因为我没有找到任何解决办法,在你说,这些似乎是我的最后选择
$Source = "d:\test\myZipFile.zip"
$Dest   = "\\REMOTE_ip\D$\test"

Copy-Item -Path $Source -Destination $Dest -Force