title: How to copy a file using Copy-Item and overwrite the file using PowerShell?
body: <p>I wan to copy a file using <code>Copy-Item</code> and overwrite it. But it returns me an error.</p>
  
  <blockquote>
    <p>Copy-Item : Cannot overwrite the item with itself</p>
  </blockquote>
  
  <pre><code>$folder = "C:\XX"
  $file = Get-ChildItem -Path "$folder\*.txt"
  $count = 1
  $Get = Get-Random -InputObject $file-Count $count | Where-Object LastWriteTime
  
  $CopyFile = Copy-Item $Get -Destination "$folder" -Recurse -Force
  </code></pre>