Import-Module from GAC for PowerShell Usage
Solution 1
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(...)
Solution 2
As long as the assembly is in the GAC, just use the strong name to reference the assembly. To get the path to the GAC be aware it has changed in .Net 4.0 http://en.wikipedia.org/wiki/Global_Assembly_Cache
$assemblyPath = 'path to the assembly file in the gac'
$fullName = [System.Reflection.AssemblyName]::GetAssemblyName($assemblyPath).FullName
[System.Reflection.Assembly]::Load($fullName)
Eric Herlitz
System developer, architect and Optimizely MVP that fancies Optimizely/Episerver, Azure, SharePoint and more. Also Co-founder of Bendsoft and the SharePoint .NET Connector. https://twitter.com/EricHerlitz http://www.herlitz.io
Updated on August 08, 2022Comments
-
Eric Herlitz almost 2 years
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?
-
RinoTom over 11 yearsOr using the full path: [System.Reflection.Assembly]::LoadFrom(...)