문제

Long time stackoverflow reader, first time poster. Forgive me if I'm not asking a question correctly.

I'm trying to use the VixCOM API with PowerShell. I don't have much experience with either. I am aware of VMWareTasks: C# VixCOM wrapper library & tools . I've used it with success, but would like to use the VixCOM API directly for reasons I don't want to get into at the moment. I may end up using the VMWareTasks wrapper, but humor me while I try to understand the issue at hand.

My script is:

$vixLib = New-Object -ComObject VixCOM.VixLib
$job = $vixLib.Connect(-1, 10, "https://esx-server/sdk", 0, "admin", "password", 0, $null, $null)

When I run this script from PowerCLI, I get an error:

Exception calling "Connect" with "9" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
At D:\dev\PowerShell\Automated Deploy\UsingVixCOM.ps1:11 char:23
+ $job = $vixLib.Connect <<<< (-1, 10, "https://esx-server/sdk", 0, "admin", "password", 0, $null, $null)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation
  • Which parameter is causing the type mismatch?
  • What is the proper way to call the Connect method?
도움이 되었습니까?

해결책

It seems like the last two parameter types are mismatched.

To display the methods and parameter types of an object call the Get-Member CmdLet like this:

$vixLib = New-Object -ComObject VixCOM.VixLib

$vixLib | get-member

Returns:

TypeName: System.__ComObject#{94eaa428-2460-470d-8f66-2a4270aff20a}  

Name                  MemberType Definition  
----                  ---------- ----------  
Connect               Method     IJob Connect (int, int, string, int, string, string, int, IVixHandle, ICallback)

You may then try to:
1. Import Interop.VixCOM.dll to get the interface types
2. Create a new class that inherits from IVixHandle
3. Create a new class that inherits from ICallback
4. Create two new instances of each of the two new classes
5. Pass those objects to the Connect method

You may need to use the get-interfaces cmdlet found on the Workarounds tab here:
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=249840&SiteID=99

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top