复制项目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。
我想复制本地文件夹(与所有子文件夹)到远程path\ ipadress \ c $ \文件夹
我该如何解决?
谢谢
$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开关,因为你已经完成了使用新psdrive的身份validation…
以具有所需权限的其他用户身份运行PowerShell窗口,并将凭据部分从脚本中提取出来。
以具有所需权限的其他用户身份运行PowerShell / cmd窗口,并使用其他实用程序而不是PS cmdlet,如robocopy。