来自GAC的Import-Module用于PowerShell用法

Eri*_*itz 8 powershell gac

我创建了一个PowerShell模块,如果我像这样加载它就可以正常工作

Import-Module "C:\temp\My.PowerShell.DocumentConversion.dll"
Run Code Online (Sandbox Code Playgroud)

我确实在全局程序集缓存中注册了该模块,但无法从那里加载它.我已经验证了模块实际上已加载到gac中.我认为像这样加载模块就足够了

Import-Module My.PowerShell.DocumentConversion.dll
Run Code Online (Sandbox Code Playgroud)

显然我错了,怎么做从gac运行powershell模块?

Sha*_*evy 18

试试Add-Typecmdlet:

Add-Type -Assembly My.PowerShell.DocumentConversion
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,请尝试使用LoadWithPartialName方法:

[System.Reflection.Assembly]::LoadWithPartialName('My.PowerShell.DocumentConversion')
Run Code Online (Sandbox Code Playgroud)

或者使用完整路径:

[System.Reflection.Assembly]::LoadFile(...)
Run Code Online (Sandbox Code Playgroud)