Shells in PowerShell?

I have the following code in C # that I am trying to connect to PowerShell. But I do not know how to transfer this order:

((_ISkypeEvents_Event)skype).CallStatus += CallStatusHandler; 

If I just typed [Skype4COM.ISkypeEvents_Event] in my PowerShell console, I get:

Cannot find type [Skype4COM.ISkypeEvents_Event]: make sure the assembly containing this type is loaded.

However, I can get all the members of the $ skype object:

 $skype = New-Object -ComObject Skype4COM.Skype 

The following line does not work:

 $skypeevent = [Skype4COM._ISkypeEvents_Event]$skype 

If I try to call the method directly on the $ skype object, for example:

 $skype.add_CallStatus({ write-host "yay" }) 

... he (as expected) tells me that:

Method call failed because [System .__ ComObject # {b1878bfe-53d3-402e-8c86-190b19af70d5}] does not contain a method named 'add_CallStatus'.

I tried to create a COM shell, but still I can’t get a type for the COM interface ...

Any ideas? Many thanks!

+4
source share
1 answer

Special PowerShell objects COM objects with its own late binding "COM adapter" to expose participants to callers (and Get-Member ). Unfortunately, this sometimes fails if it cannot find the associated type library, which usually happens when the instance is actually a remote COM object that pops up through a transparent proxy type.

Another side effect of this COM adaptation is that you are indirectly prohibited from using these types of drives to gain access to members. PowerShell typically provides a CoClass (dynamically created or PIA) class interop assembly (dynamically created or PIA) that includes members of all interfaces. In fact, this restriction on interfaces is not limited to COM objects: the ".NET Adapter" in PowerShell does not deal with the plain old .NET interfaces. Honestly, this is the preferred behavior for 99% of cases. PowerShell is a dynamic language and will always expose the true type of link at runtime. Any attempts to cast to the interface will be ignored.

This leads to more problems when you get explicitly implemented interfaces in C #. PowerShell doesn't see them at all! I made a blog about a method for proxy explicit interface members using the v2.0 module. You can try it against the COM interface, but I'm not sure if it will work.

+5
source

All Articles