Powershell v2 :: Load a COM Interop DLL

powershell, powershell-2.0

Solution

This is a 32 bit COM object and therefore you must load it from a 32 bit instance of PowerShell. To do this on a 64 bit version of Windows you can execute powershell.exe or powershell_ISE.exe in this folder: %SYSTEMROOT%\SysWow64\windowspowershell\v1.0

And, this is the complete code:

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

Problem

I have this DataLink DLL on my system - Interop.MSDASC.dll I am trying to load the same from Powershell like this - ``` [Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null ``` But, I get the following error - ``` 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 ``` How do I correctly load this ?

Original source