Here a script I'm using that works well for me.
# PowerShell script that recursively deletes all 'bin' and 'obj' (or any other specified) folders inside current folder
$CurrentPath = (Get-Location -PSProvider FileSystem).ProviderPath
# recursively get all folders matching given includes, except ignored folders
$FoldersToRemove = Get-ChildItem .\ -include bin,obj -Recurse | where {$_ -notmatch '_tools' -and $_ -notmatch '_build'} | foreach {$_.fullname}
# recursively get all folders matching given includes
$AllFolders = Get-ChildItem .\ -include bin,obj -Recurse | foreach {$_.fullname}
# subtract arrays to calculate ignored ones
$IgnoredFolders = $AllFolders | where {$FoldersToRemove -notcontains $_}
# remove folders and print to output
if($FoldersToRemove -ne $null)
{
Write-Host
foreach ($item in $FoldersToRemove)
{
remove-item $item -Force -Recurse;
Write-Host "Removed: ." -nonewline;
Write-Host $item.replace($CurrentPath, "");
}
}
# print ignored folders to output
if($IgnoredFolders -ne $null)
{
Write-Host
foreach ($item in $IgnoredFolders)
{
Write-Host "Ignored: ." -nonewline;
Write-Host $item.replace($CurrentPath, "");
}
Write-Host
Write-Host $IgnoredFolders.count "folders ignored" -foregroundcolor yellow
}
# print summary of the operation
Write-Host
if($FoldersToRemove -ne $null)
{
Write-Host $FoldersToRemove.count "folders removed" -foregroundcolor green
}
else { Write-Host "No folders to remove" -foregroundcolor green }
Write-Host
# prevent closing the window immediately
$dummy = Read-Host "Completed, press enter to continue."
Copy and paste in a new file in the same directory of your .sln file.
I call it "CleanAll.ps1" but you can call it as you prefer.
The easiest way to run it?
Right-Click on the file > Run with powershell
It recursively delete bin and obj files of all sub-folders starting from the current path. You can of course personalize and add "debug" or any other folder once you get more familiar with the script.