【发布时间】:2018-03-15 07:47:07
【问题描述】:
我正在使用此 Powershell 命令将包含许多子文件夹和文件的文件夹从本地计算机复制到远程 VM。
$session = New-PSSession -ComputerName $desComputerName -Credential $credentials
Copy-Item -Path $sourceFolder -Destination $destinationFolder -Recurse -Force -ToSession $session
大多数时候它工作得很好,一切都被复制了,但有时它不会。 这是失败时我总是得到的错误:
Copy-Item : Failed to create directory <A-Random-Folder> on remote destination.
这是完整的错误日志:
Copy-Item : Starting a command on the remote server failed with the following error message : <s:Envelope
xml:lang="en-US" xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:x="http://schemas.xmlsoap.org/ws/2004/09/transfer"
xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing" xmlns:n="http://schemas.xmlsoap.org/ws/2004/09/enumeration"
xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:p="http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd">
<s:Header><a:Action>http://schemas.dmtf.org/wbem/wsman/1/wsman/fault</a:Action><a:MessageID>uuid:BE54F3C6-3E48-40CC-882
6-29DECA14BAC7</a:MessageID><p:OperationID s:mustUnderstand="false">uuid:03909886-0D49-489B-AD87-AC5654A64257</p:Operat
ionID><p:SequenceId>1</p:SequenceId><a:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To><a:Rela
tesTo>uuid:82E5942D-D7CC-40B9-B16D-2E2A07635273</a:RelatesTo></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Receiver</s
:Value><s:Subcode><s:Value>w:InternalError</s:Value></s:Subcode></s:Code><s:Reason><s:Text
xml:lang="en-US"></s:Text></s:Reason><s:Detail><unknown></s:Detail></s:Fault></s:Body></s:Envelope> For more
information, see the about_Remote_Troubleshooting Help topic.
At MyFolder\Deploy.ps1:63 char:5
+ Copy-Item -Path $sourceFolder -Destination $destinationFolder -Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Management.Automation.PowerShell:PowerShell) [Copy-Item], PSRe
motingTransportException
+ FullyQualifiedErrorId : CopyFileRemoteExecutionError,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : Failed to create directory 'MyDestinationFolder\CKEditor\plugins\pastefromword\filter' on
remote destination.
At MySourceFolder\Deploy.ps1:63 char:5
+ Copy-Item -Path $sourceFolder -Destination $destinationFolder -Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (MyDestinationFolder\CKEditor\plugins\pastefromword\filter:String) [Copy-Item], IOException
+ FullyQualifiedErrorId : FailedToCreateDirectory,Microsoft.PowerShell.Commands.CopyItemCommand
总结一下:
- 我正在使用远程计算机的管理员凭据来初始化会话
- 复制项操作并不总是失败
- 操作创建失败的文件夹并不总是相同的
【问题讨论】:
-
不是您问题的答案,而是:您是否尝试Robocopy 完成该任务?
-
+1 用于 robocopy 解决方案。搜索 Stack Overflow 论坛,找到一些非常酷的 powershell robocopy 脚本。对我来说,我会假设它是某种网络问题(延迟/丢弃的数据包/等),这是导致问题的原因。如果不从整体上看,没有很多方法可以解决“随机”问题。
-
RoboCopy 的问题可能是没有文件共享访问目标(SMB/CIFS)。当文件共享可用时,Xcopy 对于大多数此类副本实际上工作得很好。 (Robocopy 更好,但通常不值得付出额外的努力。)