title: Powershell copy from linux samba to local windows server folder
body: <p>I need to copy a file from a Linux samba server to various Windows Server 2008.
  The shared folder has a specific login and is read-only.
  I can access and copy the shared file using Windows Explorer without a problem.</p>
  <p>But, when using PowerShell to copy the file, it always give an error as shown below.
  I have tried using Copy-item, robocopy and bitstransfer but they all give an error.</p>
  <pre><code>    $arq = &quot;file.zip&quot;
      $downloadSource = &quot;\\domain.or.ip\sharedfolder\$arq&quot;
      echo $downloadSource
  
      Copy-Item -Path &quot;$downloadSource&quot; -Destination &quot;.\$arqAgenteZabbix&quot;
  </code></pre>
  <p>this method gives me the following error</p>
  <blockquote>
  <p>Copy-Item : Access denied</p>
  <ul>
  <li>CategoryInfo          : PermissionDenied: (\domain.or.ip\sharedfolder\file.zip:String) [Copy-Item], UnauthorizedAc
  cessException</li>
  <li>FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
  ...
  Copy-Item: path not found...</li>
  </ul>
  </blockquote>
  <p>So, I tried adding a credential parameter</p>
  <pre><code>    $credencial = New-PSSession -ComputerName &quot;serverhostname&quot; -Credential &quot;serverhostname\sharedfolder&quot;
      Copy-Item -Path &quot;$downloadSource&quot; -Destination &quot;.\$arqAgenteZabbix&quot; -ToSession $credencial
  </code></pre>
  <p>But received this error after typing my password:</p>
  <blockquote>
  <p>&quot;New-PSSession : [pxl0mon00013] Fail to connect to remote server &gt;serverhostname ...
  WinRM cannot process the request... error 0x80090311 ...</p>
  <ul>
  <li>CategoryInfo          : OpenError (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
  gTransportException</li>
  <li>FullyQualifiedErrorId : AuthenticationFailed,PSSessionOpenFailed</li>
  </ul>
  </blockquote>
  <p>Then, I decided to give BitsTransfer a shot.</p>
  <pre><code>Import-Module bitstransfer
      $arq = &quot;file.zip&quot;
      $downloadSource = &quot;\\domain.or.ip\sharedfolder\$arq&quot;
  
      Start-BitsTransfer -DisplayName DownloadName `
          -TransferType Download `
          -Source $downloadSource `
          -Destination .\$arq
  </code></pre>
  <p>And it also gave me an error:</p>
  <blockquote>
  <p>Start-BitsTransfer : path not found
  '\domain.or.ip\sharedfolder\file.zip' does not exist.</p>
  <ul>
  <li>CategoryInfo          : ObjectNotFound: (\domain.or.ip\sharedfolder\file.zip:String) [Start-BitsTransfer], ParentC
  ontainsErrorRecordException</li>
  <li>FullyQualifiedErrorId : PathNotFound,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand</li>
  </ul>
  </blockquote>
  <p>How can I make this file copy, please?</p>
  <p>EDIT - 20190403</p>
  <p>I tried the following:</p>
  <pre><code>get-childitem \\domain.or.ip\sharedfolder\
  </code></pre>
  <p>which resulted in:</p>
  <pre><code>Get-ChildItem : Cannot find path '\\domain.or.ip\sharedfolder\' because it does not exist.
  At line:1 char:3
  + ls &lt;&lt;&lt;&lt;  \\domain.or.ip\sharedfolder\
      + CategoryInfo          : ObjectNotFound: (\domain.or.ip\sharedfolder\:String) [Get-ChildItem], ItemNotFo
     undException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  </code></pre>
  <p>So, I opened Explorer and pasted \domain.or.ip\sharedfolder\ at the address bar. It asked me for username and password, then, the file was available.
  After that, I returned to PowerShell and tried once again the same Get-ChildItem cmdlet. Then, I was able to list the shared folder contents as expected.</p>
  <pre><code>    Directory: \\domain.or.ip\sharedfolder
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -a---        01/04/2019     10:06    3896455 file.zip
  </code></pre>
  <p>Finally, I tried:</p>
  <pre><code>Copy-Item -Path \\domain.or.ip\sharedfolder\file.zip -Destination &quot;.\file.zip&quot;
  </code></pre>
  <p>And it was copied successfully.</p>
  <p>Well, only after I entered my login information in Explorer that PowerShell was able to find the shared folder.
  But I need it to copy without having to open explorer.</p>