title: Powershell - "Copy-item" command in scriptblock of Invoke-Command
body: <p>I need to copy file from one remote server to other using powershell script.</p>
  <p><strong>What I have tried :-</strong></p>
  <p>While i use following powershell commands it's work fine.(means file copied from one server to other)</p>
  <p><a href="https://i.stack.imgur.com/Vyjz8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vyjz8.png" alt="enter image description here" /></a></p>
  <p>But while i use following script it gives error &quot;cannot find path...&quot; as follows</p>
  <p><a href="https://i.stack.imgur.com/XnEfD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XnEfD.png" alt="enter image description here" /></a></p>
  <p>Actually, file is exist at that path.</p>
  <p>I have tried to refer following stack-overflow already question-answer</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/39224609/error-with-powershell-command-for-copying-file-to-remote-server-with-credential">Error with PowerShell command for copying file to remote server with credential</a></li>
  <li><a href="https://stackoverflow.com/questions/27844862/session-parameter-is-null-or-empty-in-powershell-script">&#39;Session&#39; Parameter is null or empty in PowerShell script</a></li>
  <li><a href="https://stackoverflow.com/questions/14468278/powershell-remote">powershell remote</a></li>
  <li><a href="https://stackoverflow.com/questions/55939872/invoke-command-with-remote-session-cannot-validate-argument-on-parameter">Invoke-Command with remote session: Cannot validate argument on parameter</a></li>
  <li><a href="https://stackoverflow.com/questions/57847446/unable-to-copy-a-binary-to-a-remote-azure-vm">Unable to copy a binary to a remote Azure VM</a></li>
  <li><a href="https://stackoverflow.com/questions/27719439/powershell-command-to-copy-file-on-remote-machine">PowerShell Command to Copy File on Remote Machine</a></li>
  </ul>
  <p>I have also tried to get help using</p>
  <pre><code> Get-Help Invoke-Command
  </code></pre>
  <p><strong>Question :-</strong></p>
  <ol>
  <li>How can i use &quot;Copy-Item&quot; command inside &quot;Invoke-Command(Scriptblock)&quot; in script(2) to copy file?</li>
  <li>Is there any better way to achieve this(means best practice)?</li>
  </ol>