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
$fileName = "C:\000\Doc1.docx" $file = New-Object -TypeName System.IO.FileInfo -ArgumentList $fileName $ErrorActionPreference = "SilentlyContinue" [System.IO.FileStream] $fs = $file.OpenWrite(); if (!$?) { $msg = "Can't open for write!" } else { $fs.Dispose() $msg = "Accessible for write!" } $msg