title: PowerShell error: Cannot move item because the item at xxx is in use
body: <p>I am using PowerShell, I need to Move-Item a folder after some operation is executed (in my case delete all empty folders).</p>
  
  <p>When I run the following script I get an error:</p>
  
  <pre><code>Move-Item : Cannot move item because the item at 'C:\Projects\xxx\aaa' is in use.
  At line:58 char:1
  + Move-Item $dist $fin
  + ~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
  </code></pre>
  
  <p>Any idea how to solve this?</p>
  
  <pre><code># delete all empty folder recursively at any levels
  do {
    $dirs = gci $tdc -directory -recurse | Where { (gci $_.fullName).count -eq 0 } | select -expandproperty FullName
    $dirs | Foreach-Object { Remove-Item $_ }
  } while ($dirs.count -gt 0)
  
  # move folder
  Move-Item $dist $fin
  Write-Host '- Moving files executed.'
  </code></pre>