As an experiment, I created $obj=new-object -com file . ("file" is a progid for the COM FileMoniker class). [Runtime.InteropServices.marshal]::GetIUnknownForObject($obj) gives me System.IntPtr on my Windows 2008R2 machine. I was able to pass this value along with the GUID for IMoniker to [Runtime.InteropServices.marshal] :: QueryInterface, and I got the same value (that is, the same pointer) as GetIUnknownForObject. So I was able to request an interface.
However, I'm not sure what is good from Powershell. There are many other methods in [Runtime.InteropServices.marshal] that may be of interest for working with COM from PS. But in general, working with COM objects in PS is very different from working with them in C ++.
EDIT Recently, I found and tested a way to access some COM components from PS that might be of interest here. The Windows SDK comes with a large set of IDL files. If you want to access one of them (and the component does not implement IDispatch), you can compile IDL using MIDL, and then use TLBIMP to create the interop assembly. I have successfully done this with the three VSS hardware vendor interfaces.
I also found out that you can use [type] :: GetTypeFromCLSID to get the type from the CLSID. And depending on the component, you can create it.
Ξ§pαΊ
source share