GAC import module for using PowerShell

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

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

I also registered the module in the global build cache, but cannot load it. I checked that the module is actually loaded in gac. I realized that it would be enough to load a module like this

 Import-Module My.PowerShell.DocumentConversion.dll 

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

+7
source share
2 answers

Try the Add-Type cmdlet:

 Add-Type -Assembly My.PowerShell.DocumentConversion 

If it does not work, try the LoadWithPartialName method:

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

Or using the full path:

 [System.Reflection.Assembly]::LoadFile(...) 
+15
source

While the assembly is in the GAC, just use a strong name to refer to the assembly. To get the path to the GAC, keep in mind that 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) 
+2
source

All Articles