Registering a DLL assembly in the GAC using Powershell

 

If you are managing Sharepoint or Active Directory Federation Services, you sometimes have to register DLLs in the GAC without your supplier providing you a nice MSI installer to do so.

Once solution would be use gacutil but it is now a .Net Framework Utility, and you may not want to copy it on your servers. To accomplish the same thing using Powershell solely, you may run these lines:

<pre class="lang:ps decode:true " title="Assembly registration in GAC in Powershell">[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publisher = New-Object System.EnterpriseServices.Internal.Publish
$publisher.GacInstall("C:\path\MydllToRegister.dll")

Don not forget that you can retrieve many properties of the assembly, such as the public token, just by loading it:

<pre class="lang:ps decode:true " title="Retrieving Properties of an Assembly">([system.reflection.assembly]::loadfile("C:\path\MydllToRegister.dll")).FullName