Ade*_*SIF 9 scripting windows powershell windows-server-2012 windows-server-2012-r2
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
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
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
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
Start-BitsTransfer -Source $source -Destination $Destination -Credential $credentials
Run Code Online (Sandbox Code Playgroud)
而且 Robocopy 不支持凭据...
我在 Windows 7 上运行 Powershell V4.0,我的服务器也在 Windows server 2012 r2 和 powershell V4.0 上运行。
我想将本地文件夹(包含所有子文件夹)复制到远程路径 \ipadress\c$\folder
我该如何解决?
谢谢
Blu*_*ute 14
$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
Run Code Online (Sandbox Code Playgroud)
编辑:愚蠢的错误,您可以省略 copy-item cmdlet 上的 -credential 开关,因为您已经使用 new-psdrive 完成了身份验证...
| 归档时间: |
|
| 查看次数: |
14370 次 |
| 最近记录: |