Remove-Item in use by another process

Hi,

I am trying to delete users’ home folders who no longer have an AD account. I found that Remove-Item only works properly if you use Get-ChildItem first and pipe it to Remove-Item.

This is the command I am using:

Get-ChildItem c:\whatever -Recurse -force | Remove-Item -force -recurse -Confirm:$true

It properly deletes the folder contents (including Favorites), but it does not delete the folder itself. I then try to delete it using Remove-Item but it says the folder is being used by another process.

Does anyone know how to get around this issue?

Thanks!

 

Was the profile recently created? Some windows service might be processing it.

Thanks I found out that was an apache process :frowning:

Thanks!