Home > Software design >  Delete a locked file using powershell
Delete a locked file using powershell

Time:10-13

Here is a script to remove file/folder older than X days. but then i thought what if any of file or folder is being using by other app. i haven't face such issue yet but i don't think Remove-Item cannot delete file/folder if it's locked/using by other app. is there anyway using powershell we can delete locked file?

Get-ChildItem "folder path" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-1))}| Remove-Item -Recurse -Force -Confirm:$false

CodePudding user response:

Remove-Item

will delete the locked files as well. Please validate

  • Related