17 April 2012

PowerShell Script for Removing All Assemblies in a Folder

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. 

Keep up to date with Simple-Talk

For more articles like this delivered fortnightly, sign up to the Simple-Talk newsletter

This post has been viewed 1902 times – thanks for reading.

  • Rate
    [Total: 0    Average: 0/5]
  • Share

Damon Armstrong

Damon Armstrong is a Senior Engineering Team Lead with GimmalSoft in Dallas, Texas, and author of Pro ASP.NET 2.0 Website Programming. He specializes in Microsoft technologies with a focus on SharePoint and ASP.NET. When not staying up all night coding, he can be found playing disc golf, softball, working on something for Carrollton Young Life, or recovering from staying up all night coding.

View all articles by Damon Armstrong