$locked = $true while ($locked) { try { $file = New-Object System.IO.FileInfo $Path [IO.File]::OpenWrite($file).close(); $locked = $false } catch { # file is locked by a process. Start-Sleep -s 1000 } }