PowerShell Script to install assembly in GAC on Windows Server 2019

Hi All,
Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂
Today very small script – to add / install assembly into GAC on Windows server onwords. As I need to search bit so thought to share. SHARING IS CARING 🙂
Prior to Windows Server 12 there were very easy way to add / install assembly into GAC – just drag and drop into assembly folder by opening in Windows Explorer
But for Windows Server 19 there is no simple drag and drop way and no GACUtil.exe directly available on server
Detailed Steps :
- Run the SharePoint PowerShell console as administrator
- Load the assembly – System.EnterpriseServices using Load method as
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
- The namespace System.EnterpriseServices.Internal has a class called Publish which has a method GacInstall (string – assembly path) – Installs assembly in to Global assembly cache – https://docs.microsoft.com/en-us/dotnet/api/system.enterpriseservices.internal.publish.gacinstall?view=netframework-4.8#System_EnterpriseServices_Internal_Publish_GacInstall_System_String_
- Instantiate the class – System.EnterpriseServices.Internal.Publish using New-Object as
$objPublish = New-Object System.EnterpriseServices.Internal.Publish
- Once we have instance of System.EnterpriseServices.Internal.Publish class we are ready to call the method GacInstall(file path of assembly)
$objPublish.GacInstall("D:\PS\missing dlls\Microsoft.Practices.SharePoint.Common.dll")
- As usual to have effect we need to do IISRESET

Complete Script :
PS C:\Users\prasham> [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
PS C:\Users\prasham> $objPublish = New-Object System.EnterpriseServices.Internal.Publish
PS C:\Users\prasham> $objPublish.GacInstall("D:\PS\missing dlls\Microsoft.Practices.SharePoint.Common.dll")
PS C:\Users\prasham> iisreset
Thanks for reading 🙂 Enjoy the beautiful life 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂
You must be logged in to post a comment.