Windows

複製項文件系統提供程序錯誤

  • June 27, 2014

Copy-item 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 Server 2012 r2 上執行,同時帶有 powershell V4.0。

我想將本地文件夾(包含所有子文件夾)複製到遠端路徑 \ipadress\c$\folder

我該如何解決?

謝謝

$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

編輯:愚蠢的錯誤,您可以省略複製項 cmdlet 上的 -credential 開關,因為您已經使用 new-psdrive 完成了身份驗證…

引用自:https://serverfault.com/questions/608175