复制项FileSystem提供程序错误

Modified on: Fri, 16 Aug 2019 00:20:02 +0800

复制项cmdlet未按预期工作,我不明白为什么。这是我的代码:

$Source = "C:\folder1"
$Destination = "\\172.22.0.115\c$\folder2\"
$Password  = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword"
$User = "Domain\Administrator"
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

Copy-Item $Source -Destination $Destination -Credential $credentials 

这是我得到的错误:

The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform 
the operation again without specifying credentials.
At C:\Sans titre2.ps1:7 char:1
+ Copy-Item $Source -Destination $Destination -Credential $credentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported

我也试过这个:

Start-BitsTransfer -Source $source -Destination $Destination -Credential $credentials

Robocopy不支持凭据......

我在Windows 7上运行Powershell V4.0,我的服务器也运行在Windows服务器2012 r2上,还有PowerShell V4.0。

我想将本地文件夹(包含所有子文件夹)复制到远程路径\ ipadress \ c $ \ folder

我该如何解决?

由于

作者:,Adeel ASIF

最佳答案

$Source = "C:\folder1"
$Destination = "X:\"
$Password  = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword"
$User = "Domain\Administrator"
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

New-PSDrive -Name X: -PSProvider FileSystem -Root "\\172.22.0.115\c$\folder2" -Credential $credentials

Copy-Item $Source -Destination $Destination

编辑:愚蠢的错误,您可以省略copy-item cmdlet上的-credential开关,因为您已经使用new-psdrive完成了auth ...

作者:,BlueCompute

相关问答

添加新评论