Skip to content

Instantly share code, notes, and snippets.

@TimothyK
Created July 25, 2025 20:36
Show Gist options
  • Select an option

  • Save TimothyK/0b9d5d96b4a17e9422b0b7d34eb12633 to your computer and use it in GitHub Desktop.

Select an option

Save TimothyK/0b9d5d96b4a17e9422b0b7d34eb12633 to your computer and use it in GitHub Desktop.
PowerShell script to remove bin and obj folders resursively
##############
# Parameters
##############
param (
[Parameter(Mandatory = $true)]
[string] $folderPath
)
# Functions
function Remove-BinAndObjFolders {
param (
[string]$path
)
# Check if the path exists
if (Test-Path $path) {
# Get all subdirectories in the current directory
$subDirectories = Get-ChildItem -Path $path -Directory
# Loop through each subdirectory
foreach ($directory in $subDirectories) {
# Check if the directory name is "bin" or "obj"
if ($directory.Name -eq "bin" -or $directory.Name -eq "obj") {
# Delete the directory
Remove-Item -Path $directory.FullName -Recurse -Force
Write-Host "Deleted $($directory.FullName)"
}
else {
# If it's not "bin" or "obj", recursively call the function
Remove-BinAndObjFolders -path $directory.FullName
}
}
}
else {
Write-Host "Path $path does not exist."
}
}
# Main
Remove-BinAndObjFolders -path $folderPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment