title: Powershell: Check if a file is locked
body: <p>I have a problem with automating a deployment, after I stop the service there is still a lock on the file and I am unable to delete it. I really do not want to start hacking about with sleeps to make something that 'usually works'. Is there a good way to properly resolve the problem of locked files, perhaps some kind of 'wait until file is removable':</p>
  
  <p>Get-ChildItem : Access to the path 'D:\MyDirectory\' is denied.</p>
  
  <p>'Test-Path' is not sufficient in this case as the folder both exists and I have access to it.</p>