Sunday, September 22, 2013

An Even Better Way to Add Files to the GAC–PowerShell GAC Module

PowerShell is magic in many ways but today I was impressed by yet another community project.  There are so many of these lying around and with PowerShell they are pretty simple to cobble together into a nice solution.  In this case I used the module below to create a custom resource for Desired State Configuration. 

Here’s the module I’m referring to:

PowerShell GAC Module on CodePlex

This is a really nice module including documentation and samples, not to mention it just works.  Adding it to my toolbox for FIM deployments.  With this module it would be very simple to clean up the scripts that create the ActivityInformationConfiguration objects in the FIM Service.  My plan is to create a resource for AIC’s in DSC such that I only need to declare them (no more scripting the configuration).

Here’s a snippet from the PowerShell GAC project samples to show how nice it is:

# Show the assemblies in the GAC, including the file version

Get-GacAssembly SomeCompany* | Format-Table -View FileVersion


# Backup the assemblies in C:\Temp\SomeCompany

Get-GacAssembly SomeCompany* | Get-GacAssemblyFile | Copy-Item -Destination C:\Temp\SomeCompany


# Remove the assemblies from the GAC

# Can only be run from an elevated prompt

Get-GacAssembly SomeCompany* | Remove-GacAssembly


# Add the assemblies back to the GAC

# Can only be run from an elevated prompt

Add-GacAssembly C:\Temp\SomeCompany\*.dll


No comments: