I need a powershell script which will delete all bin and obj folders in all the sub…
- User
I need a powershell script which will delete all bin and obj folders in all the sub directories starting from a root folder
- Assistant
You can use the following PowerShell script to delete all bin and obj folders in all subdirectories starting from a given root folder:
powershell$rootFolder = "C:\YourRootFolder" #Replace with your root folder path Get-ChildItem -Path $rootFolder -Recurse -Force -Directory | ForEach-Object { if ($_.Name -eq "bin" -or $_.Name -eq "obj") { Write-Host "Deleting folder $($_.FullName)" Remove-Item -Path $_.FullName -Recurse -Force } }This script sets the
$rootFoldervariable to the path of your root folder. It then usesGet-ChildItemwith the-Recurseflag to find all directories inside the root folder, iterates over them usingForEach-Object, checks if the name of a directory is eitherbinorobjand, if it is, writes the target folder to the console and removes it usingRemove-Item.Remember to replace "C:\YourRootFolder" with the actual path to your root folder before executing the script.