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?
To import the module into all sessions, add an Import-Module command to your PowerShell profile. To manage remote Windows computers that have PowerShell and PowerShell remoting enabled, create a PSSession on the remote computer and then use Get-Module -PSSession to get the PowerShell modules in the PSSession.
The Global Assembly Cache (GAC) is a machine wide repository for . Net Assemblies. PowerShell GAC provides several PowerShell commands to view and modify the GAC. PowerShell GAC works standalone and does not depend on tools like gacutils.exe.
How to Import a Module into Every Session. The Import-Module command imports modules into your current PowerShell session. To import a module into every PowerShell session that you start, add the Import-Module command to your PowerShell profile. For more information about profiles, see about_Profiles.
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(...)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With