Saturday, May 24, 2008

Delete undeletable file with Powershell

I just came across a situation where I wanted to delete a file in a folder and I couldn't do so because the file was allegedly in use. I still needed to delete this file and tried a few things but was unsuccessful.

I dropped into Powershell and tried the Remove-Item call on the file which failed as well. I then tried the following sequence which worked like a dream:

$item = Get-Item FileToDelete.dll
$itemInfo = New-Object System.IO.FileInfo $item

And that was it, the file is now gone.

No comments:

Post a Comment