RemoveItem's -Recurse Bug
tl;dr: There is no solution and it will probably never be fixed.
Why Remove-Item -Recurse
doesn’t work 100% of the time on Windows.
More accurately, I’ve wondered why Microsoft won’t fix it. However, this video shows that file deletes are not synchronous and that delete doesn’t really delete. Instead, delete is mark to delete later. This is a leftover feature from it’s VMX days and was a DOD requirement.
This Github thread has a good discussion on it, and it actually asks, “What does shift+del do that Remove-Item -recurse doesn’t?” which I’ve wondered for a while.
As far as I understand this, it’s not exactly a Powershell issue or bug, and the Powershell team isn’t going to waste time to work around it. Especially since it’s not an issue on the *nix side, and it looks like this bug may be encountered less frequently in Win10 1909+.
It’s still annoying and stupid.