If you want to recursively delete a directory/folder using PowerShell, then you have 2 options.

I needed this when cleaning up build artifacts in a CI pipeline running on Windows. The first option with -LiteralPath is safer because it handles special characters in folder names (like brackets) that would trip up the normal path resolution. The second option deletes the contents but keeps the parent folder, which is useful when you want to empty a directory without removing it.

Watch out for long path issues on Windows — if any file path exceeds 260 characters, the delete will fail silently. In that case, use robocopy with an empty directory as a workaround.

Option 1 – With LiteralPath and Force

Remove-Item -LiteralPath "myFolder" -Force -Recurse

Option 2 – With implicit and Recurse

Remove-Item myFolder/* -Recurse