title: Copy-Item for copy files from local to remove server using credentials
body: <p>I am trying to copy some files and folder from my local machine to a remote server:</p>
  
  <pre><code>Copy-Item .\copy_test.txt -destination "\\serverip\c$\backups\"
  </code></pre>
  
  <p>but I'm getting an error:</p>
  
  <pre>Copy-Item : Logon failure: unknown user name or bad password.
  At line:1 char:10
  + Copy-Item &lt;&lt;&lt;&lt;  .\copy_test.txt -destination "\\serverip\c$\backups\" -verbose
      + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
      + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand</pre>
  
  <p>I was trying using credentials but this command does not allow <code>-Credential</code> argument. I was searching a lot and in every example the command is pretty easy just executing the <code>Copy-Item $source -destination $destination</code> and I wonder why is so hard in my workstation.</p>
  
  <h2>Creating New PSDrive</h2>
  
  <p>I tried to create a <code>New-PSDrive</code> but it didn't work. </p>
  
  <pre><code>$creds = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password
  
  New-PSDrive -Name X -PSProvider FileSystem -Root '\\$serverip\c$' -Credential $creds -Persist
  Copy-Item '.\copy_test.txt' -Destination 'X:\backups'
  Remove-PSDrive -Name X
  </code></pre>
  
  <p>It is the error message:</p>
  
  <pre>PS C:\Users\Administrator\Desktop> .\copyfiles.ps1
  New-PSDrive : The network path was not found
  At C:\Users\Administrator\Desktop\copyfiles.ps1:11 char:1
  + New-PSDrive -Name X -PSProvider FileSystem -Root '\\$serverip\c$' -Credential $c ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (X:PSDriveInfo) [New-PSDrive], Win32Exception
      + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveC
  
  Copy-Item : Cannot find drive. A drive with the name 'X' does not exist.
  At C:\Users\Administrator\Desktop\copyfiles.ps1:12 char:1
  + Copy-Item '.\copy_test.txt' -Destination 'X:\backups'
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (X:String) [Copy-Item], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
  
  Remove-PSDrive : Cannot find drive. A drive with the name 'X' does not exist.
  At C:\Users\Administrator\Desktop\copyfiles.ps1:13 char:1
  + Remove-PSDrive -Name X
  + ~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (X:String) [Remove-PSDrive], DriveNotFoundExcepti
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand</pre>
  
  <h2>My servers</h2>
  
  <p>My server are windows instances in AWS. I have the right permission because I am able to run other command like <code>Invoke-Command</code> in order to inspect some services into the remote server.</p>
  
  <pre>PS> $PSVersionTable.PSVersion
  
  Major  Minor  Build  Revision
  -----  -----  -----  --------
  4      0      -1     -1</pre>