简体   繁体   English

PowerShell DSC加载程序集

[英]PowerShell DSC load assembly

I have written a class based DSC resource. 我已经写了一个基于类的DSC资源。 In this resource I need an assembly(Microsoft.SqlServer.Smo.dll). 在此资源中,我需要一个程序集(Microsoft.SqlServer.Smo.dll)。 I have tried to load the assembly with the manifest file: like that: RequiredAssemblies = @("Microsoft.SqlServer.Smo.dll") 我试图用清单文件加载程序集:像这样: RequiredAssemblies = @("Microsoft.SqlServer.Smo.dll")

Now I have the problem that when I want to write my DSC Configuration definion, I can't load my dsc resource because of the erromessage: Unable to find type [Microsoft.SqlServer.Smo.Login] 现在,我遇到一个问题,当我想编写DSC配置定义时,由于出现错误而无法加载dsc资源:无法找到类型[Microsoft.SqlServer.Smo.Login]

Picture of the errormessage: 错误消息的图片: 在此处输入图片说明

How can I load an assembly into my dsc session? 如何将程序集加载到dsc会话中?

Make sure that assembly is in the same folder as your module, and then call it like this (no dll): RequiredAssemblies = @("Microsoft.SqlServer.Smo") 确保程序集与模块位于同一文件夹中,然后按以下方式调用它(无dll): RequiredAssemblies = @("Microsoft.SqlServer.Smo")

If that doesn't work, you can use reflection and load it into your AppDomain when the module is imported. 如果这不起作用,则可以在导入模块时使用反射并将其加载到AppDomain中。

$assembly = Join-Path $PSScriptRoot -ChildPath 'Microsoft.SqlServer.Smo.dll'
$result = [System.Reflection.Assembly]::LoadFile($assembly)
if($result -eq $null)
{
    throw New-Object System.Exception("Failed to Microsoft.SqlServer.Smo assembly")            
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在Powershell中加载.NET程序集 - Unable to load .NET assembly in Powershell 无法在 PowerShell 7 中加载 .NET 程序集 - Unable to load a .NET assembly in PowerShell 7 无法在Powershell远程会话中加载文件或程序集 - Could not load file or assembly in powershell remote session 在Powershell中加载注册的外部程序集(dll) - Load registered external assembly (dll) in Powershell 如何在新的Powershell窗口中加载部件 - how to load an assembly in a new powershell window 如何在没有Powershell的情况下创建和执行DSC - How to create and execute dsc without powershell 在 PowerShell 中加载 WinSCP - 无法加载文件或程序集 - 此程序集由比当前加载的运行时更新的运行时构建 - Loading WinSCP in PowerShell - Could not load file or assembly - This assembly is built by a runtime newer than the currently loaded runtime 如何在 PowerShell 2.0 中加载 WinSCPnet.dll 程序集? (此程序集由比当前加载的运行时更新的运行时构建) - How to load WinSCPnet.dll assembly in PowerShell 2.0? (This assembly is built by a runtime newer than the currently loaded runtime) PowerShell DSC,服务器 2019,.NET 3.5 无法从源安装 - PowerShell DSC, Server 2019, .NET 3.5 failing to install from source Powershell 配置程序集重定向 - Powershell config assembly redirect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM