How to quietly remove a directory with content in PowerShell

ID : 10447

viewed : 68

Tags : powershelldirectorypowershell

Top 5 Answer for How to quietly remove a directory with content in PowerShell

vote vote

96

Remove-Item -LiteralPath "foldertodelete" -Force -Recurse 
vote vote

85

From PowerShell remove force answer: help Remove-Item says:

The Recurse parameter in this cmdlet does not work properly

The command to workaround is

Get-ChildItem -Path $Destination -Recurse | Remove-Item -force -recurse 

And then delete the folder itself

Remove-Item $Destination -Force  
vote vote

74

This worked for me:

Remove-Item $folderPath -Force  -Recurse -ErrorAction SilentlyContinue 

Thus the folder is removed with all files in there and it is not producing error if folder path doesn't exists.

vote vote

65

2018 Update

In the current version of PowerShell (tested with v5.1 on Windows 10 1809) one can use the simpler Unix syntax rm -R .\DirName to silently delete the directory .\DirName with all subdirectories and files it may contain. In fact many common Unix commands work in the same way in PowerShell as in a Linux command line.

vote vote

58

To delete content without a folder you can use the following:

Remove-Item "foldertodelete\*" -Force -Recurse 

Top 3 video Explaining How to quietly remove a directory with content in PowerShell

Related QUESTION?