I'm attempting to programmatically start a Hyper-V VM using C#'s System.Management API. I've had great success creating and configuring the VM, however starting the VM has proven elusive.
I get a Msvm_ComputerSystem object, using a helper method to perform the WQL query:
ManagementObject compSys = WMIHelpers.GetMsvm_ComputerSystem(scope, vmName);
The method to change the VM state is (allegedly) "RequestStateChange" and I am able to get the parameters object and set them:
ManagementBaseObject callParams = compSys.GetMethodParameters("RequestStateChange");
callParams["RequestedState"] = WMIHelpers.RequestedState.Enabled;
However when I invoke the method, my return value is 1, which is undocumented:
ManagementBaseObject result = vsServ.InvokeMethod("RequestStateChange", callParams, null);
if(result["ReturnValue"] == 1)
{
System.Console.WriteLine("WTF?!?");
}
I have no idea what I'm doing wrong here, or why I'm getting this undocumented return value.