title: Powershell Delete Locked File But Keep In Memory
body: <p>Until recently, we've been deploying .exe applications by simply copying them manually to the destination folder on the server.  Often though, the file was already running at the time of deployment  (the file is called from a SQL Server job)--sometimes even multiple instances.  We don't want to kill the process while it's running.  We also can't wait for it to finish because it keeps on being invoked, sometimes multiple times concurrently.</p>
  
  <p>As a workaround, what we've done is a "cut and paste" via Windows Explorer on the .exe file into another folder.  Apparently, what this does is it moves the file (effectively a delete) but keeps it in RAM so that the processes which are using it can continue without issues.  Then we'd put the new files there which would get called when any later program would call it. </p>
  
  <p>We've now moved to an automated deploy tool and we need an automated way of doing this.</p>
  
  <pre><code>Stop-Process -name SomeProcess
  </code></pre>
  
  <p>in PowerShell would kill the process, which I don't want to do.</p>
  
  <p>Is there a way to do this?
  (C# would also be OK.)</p>
  
  <p>Thanks,</p>