Alexander Anikin's blog

My personal blog

Install bunch of DLL files to Windows Server 2012 GAC

leave a comment »

Thanks to http://devlicio.us/blogs/christopher_bennage/archive/2010/08/25/powershell-gac-and-build-servers.aspx

1. Create ps1 script with contents:

if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq “System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” }) ) {

[System.Reflection.Assembly]::Load(“System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”) | Out-Null
}

$publish = New-Object System.EnterpriseServices.Internal.Publish

Foreach ($file in Get-Childitem “*.dll” -recurse -force)
{
Write-Host $file

$assembly = $null

if ( $file -is [string] ) {
$assembly = $file
} elseif ( $file -is [System.IO.FileInfo] ) {
$assembly = $file.FullName
} elseif ( $file -is [System.IO.DirectoryInfo] ) {
Continue
} else {
#throw (“The object type ‘{0}’ is not supported.” -f $file.GetType().FullName)
}

if ( -not (Test-Path $assembly -type Leaf) ) {
throw “The assembly ‘$assembly’ does not exist.”
}

if ( [System.Reflection.Assembly]::LoadFile( $assembly ).GetName().GetPublicKey().Length -eq 0 ) {
throw “The assembly ‘$assembly’ must be strongly signed.”
}

Write-Output “Installing: $assembly”

$publish.GacInstall( $assembly )
}

2.  Place it to folder with DLLs and start.

PS You can use set-executionpolicy remotesigned to switch running scripts on.

Written by Alex Anikin

September 13, 2013 at 7:57 am

Posted in .Net, Windows Server

Leave a comment