I am trying to delete a folder with subfolders/files.
Remove-Item -Force -Recurse -Path $directoryPath
I am getting the error Cannot remo
You could try the following:
Remove-Item -Force -Recurse -Path "$directoryPath\*"
Note when using the -Recurse
parameter with -Include
in Remove-Item
, it can be unreliable. So it's best to recurse the files first with Get-ChildItem
and then pipe into Remove-Item
. This may also help if you deleting large folder structures.
Get-ChildItem $directoryPath -Recurse | Remove-Item -Force