Powershell v2 ::加载COM Interop DLL

Ang*_*wal 3 powershell powershell-2.0

我在我的系统上有这个DataLink DLL - Interop.MSDASC.dll我试图从像这样的Powershell加载相同的 -

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误 -

Exception calling "LoadFile" with "1" argument(s): "Could not load file or assembly 'Interop.MSDASC.dll' or one of its dependencies.  is not a 
valid Win32 application. (Exception from HRESULT: 0x800700C1)"
At line:1 char:32
+ [Reflection.Assembly]::LoadFile <<<< ("C:\Interop.MSDASC.dll") | out-null
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
Run Code Online (Sandbox Code Playgroud)

我该如何正确加载?

Ang*_*wal 9

这是一个32位COM对象,因此您必须从32位PowerShell实例加载它.要在64位版本的Windows上执行此操作,您可以在此文件夹中执行powershell.exe或powershell_ISE.exe:%SYSTEMROOT%\ SysWow64\windowspowershell\v1.0

而且,这是完整的代码:

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") 
$dataLinkInstance = new-object MSDASC.DataLinksClass
$dataLinkInstance.WriteStringToStorage("C:\\FrmPowershell.udl", "Provider=SQLOLEDB.1;", 2)
Run Code Online (Sandbox Code Playgroud)