Click here to monitor SSC

Caffeine Induced Tirades about .NET and Life

PowerShell Script for Removing All Assemblies in a Folder

Published 17 April 2012 1:33 pm

You may have seen my blog post on how to add all of the assemblies from a folder into the GAC.  Here is a quick PowerShell script to do the reverse – it looks through a list of assemblies in a folder and removes them from the GAC:

$gacUtilLocation = "C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinx64gacutil.exe";

get-childitem * -include *.dll,*.exe | foreach-object {
    Write-Host "Removing" $asm.FullName
    $asm = [System.Reflection.Assembly]::LoadFile($_)
    $command = "&`"{0}`"/nologo /u `"{1}`"" -f $gacUtilLocation,$asm.FullName   
    invoke-expression $command
}

I find this helpful in SharePoint to make sure the GAC is clear of any of my development assemblies before doing a proper deployment from a WSP. 

Leave a Reply