title: Powershell Copy-Item to remote session fails randomly
body: <p>I'm using this Powershell command to copy a folder, which contains many sub-folders and files from my local machine to a remote VM.</p>
  
  <pre><code>$session = New-PSSession -ComputerName $desComputerName -Credential $credentials
  Copy-Item -Path $sourceFolder -Destination $destinationFolder -Recurse -Force -ToSession $session
  </code></pre>
  
  <p>Most of the times it works just fine, everything is copied, but sometimes it doesn't.
  This is the error I always get when it fails: </p>
  
  <pre><code>Copy-Item : Failed to create directory &lt;A-Random-Folder&gt; on remote destination.
  </code></pre>
  
  <p>Here's the full error log:</p>
  
  <pre><code>Copy-Item : Starting a command on the remote server failed with the following error message : &lt;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"&gt;
  &lt;s:Header&gt;&lt;a:Action&gt;http://schemas.dmtf.org/wbem/wsman/1/wsman/fault&lt;/a:Action&gt;&lt;a:MessageID&gt;uuid:BE54F3C6-3E48-40CC-882
  6-29DECA14BAC7&lt;/a:MessageID&gt;&lt;p:OperationID s:mustUnderstand="false"&gt;uuid:03909886-0D49-489B-AD87-AC5654A64257&lt;/p:Operat
  ionID&gt;&lt;p:SequenceId&gt;1&lt;/p:SequenceId&gt;&lt;a:To&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/a:To&gt;&lt;a:Rela
  tesTo&gt;uuid:82E5942D-D7CC-40B9-B16D-2E2A07635273&lt;/a:RelatesTo&gt;&lt;/s:Header&gt;&lt;s:Body&gt;&lt;s:Fault&gt;&lt;s:Code&gt;&lt;s:Value&gt;s:Receiver&lt;/s
  :Value&gt;&lt;s:Subcode&gt;&lt;s:Value&gt;w:InternalError&lt;/s:Value&gt;&lt;/s:Subcode&gt;&lt;/s:Code&gt;&lt;s:Reason&gt;&lt;s:Text 
  xml:lang="en-US"&gt;&lt;/s:Text&gt;&lt;/s:Reason&gt;&lt;s:Detail&gt;&lt;unknown&gt;&lt;/s:Detail&gt;&lt;/s:Fault&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt; 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
  </code></pre>
  
  <p>To Sum up:</p>
  
  <ul>
  <li>I'm using the remote computer's administrator credential to initialize the session</li>
  <li>The Copy-Item operation does not always fail</li>
  <li>The folder where the operation fails to create is not always the same</li>
  </ul>