title: Copy-Item from UNC path located in a different domain
body: <p>I have been given a task to install a software(msi) across servers (2008,2012,2016) that are scattered across several domains. The trick is to copy the installation, configuration files from a UNC that is located in a different domain to each server locally. Different PowerShell version behave in different ways.
  Initially on Server 2016s I tried <strong>New-PSSession</strong> and <strong>-FromSession</strong> switch to establish a connection to the server (successfully) that had the UNC path and copy like so:</p>
  
  <pre><code>$creds = Get-Credential -Username "&lt;domain_with_unc_share&gt;\$($env:username)"
  $unc_server_session = New-PSSession -ComputerName unc_server -Credential $creds
  Copy-Item "d:\share\*.*" -Destination "c:\temp\" -FromSession $unc_server_session -Recurse
  </code></pre>
  
  <p><strong>-FromSession</strong> switch was introduced with PS5 and works well with Sevrer 2016 but anything lower and this fails. This clearly does not work for Windows 2008/2012.</p>
  
  <p>I then tried to use just a UNC in Copy-Item like so:</p>
  
  <pre><code>$creds = Get-Credential -Username "&lt;domain_with_unc_share&gt;\$($env:username)"
  Copy-Item "\\unc_server\share\*.*" -Destination "c:\temp\" -Credential $creds -Recurse
  </code></pre>
  
  <p>This gives me an error that <strong>-Credential</strong> switch cannot be used with <strong>Copy-Item</strong> and defers to using <strong>New-PSDrive</strong></p>
  
  <pre><code>Copy-Item : Cannot retrieve the dynamic parameters for the cmdlet. The FileSystem provider supports credentials only
  on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.
  At line:1 char:1
  + Copy-Item "\\unc_server\share\ ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindingException
      + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.CopyItemCommand
  </code></pre>
  
  <p>I then tried the following:</p>
  
  <pre><code>$creds = Get-Credential -Username "&lt;domain_with_unc_share&gt;\$($env:username)"
  New-PSDrive -Name Y -PSProvider filesystem -Root "\\unc_server\share" -Credential $creds
  Copy-Item "Y:\*.*" -Destination "c:\temp\" -Recurse
  </code></pre>
  
  <p>Still not happy, it tells me that my UNC path does not exist:</p>
  
  <pre><code>New-PSDrive : The specified drive root "\\unc_server\share"
  either does not exist, or it is not a folder.
  At line:1 char:1
  + New-PSDrive -Name "Y" -PSProvider filesystem -Root "\\unc_server\share ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ReadError: (Y:PSDriveInfo) [New-PSDrive], IOException
      + FullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand
  </code></pre>
  
  <p>I am a loss as to how to appease the PowerShell God so it works across PS3,4,5.
  Any suggestions?</p>