Import-Module from GAC for PowerShell Usage

Eric Herlitz picture Eric Herlitz · Feb 12, 2013 · Viewed 11.5k times · Source

I have created a powershell module that works just fine if I load it like this

Import-Module "C:\temp\My.PowerShell.DocumentConversion.dll"

I did register the module in the global assembly cache as well but can't load it from there. I have verified that the module in fact is loaded in the gac. I figured that it would be sufficient to load the module like this

Import-Module My.PowerShell.DocumentConversion.dll

Obviously I was wrong, how do one do to run powershell modules from gac?

Answer

Shay Levy picture Shay Levy · Feb 12, 2013

Try the Add-Type cmdlet:

Add-Type -Assembly My.PowerShell.DocumentConversion

If it's not working try the LoadWithPartialName method:

[System.Reflection.Assembly]::LoadWithPartialName('My.PowerShell.DocumentConversion')

Or using the full path:

[System.Reflection.Assembly]::LoadFile(...)