Cleaning bin and obj folders – Powershell

Every now and then I come to the point that I want to delete everything from the bin, obj and Temporary Internet Files…
I also have to kill all my processes, so that it gets really a clean start.
I wrote a powershell script that does it for me…

$deleteIisExpressConfigs = Read-Host "Delete IIS Express Configs [n]"
if($deleteIisExpressConfigs.Contains("y"))
{
    write-host "Deleting IIS Express Config files"
    set-location "$env:userprofile\documents\iisexpress\config\"
    Get-ChildItem |    
    %{
        Write-Host "Deleting: " $_.FullName 
        Remove-Item $_.FullName -Force
     }
}

Write-Host "Killing iisexpress processes"
Stop-Process -processname iisexpress*

Write-Host "Deleting 'bin' and 'obj' folders of your solution directory"
$solutionDir = "C:\Projects"
Set-Location $solutionDir
Get-ChildItem -Recurse | 
    ?{ $_.PSIsContainer -and ( $_.Name -eq "bin" -or $_.Name -eq "obj") } | 
    %{
        Write-Host "Deleting: " $_.FullName 
        Remove-Item $_.FullName -Recurse -Force
     }
 
Write-Host "Deleting Temporary ASP.Net files"
 
$dotnetFolder = "C:\Windows\Microsoft.NET"
Set-Location $dotnetFolder
Get-ChildItem -Recurse | 
    ?{ $_.PSIsContainer -and $_.Name -eq "Temporary ASP.NET Files" } | 
    %{
        Write-Host "Deleting contents of: " $_.FullName 
        Set-Location $_.FullName
        Get-ChildItem | % { Remove-Item $_.FullName -Recurse -Force }
     }
Advertisements

About Tamas Nemeth

Husband and proud father of two daughters in Nürnberg. I'm working as a Senior Software Developer and an enthusiastic Clean-Coder. I spend most of my free time with my family (playing, hiking, etc...). I also play table-tennis and badminton sometimes...
This entry was posted in Technical Interest and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s