Hi everyone,
I made a code to create a schedule task using the SDK, but I have errors:
Here is my code:
// Find the virtual machine list from the virtual machine folder found above.
ManagedObjectReference] vmList = (ManagedObjectReference[)getObjectProperty(vmFolderRef, "childEntity");
//Searching for the template/virtual machine
ManagedObjectReference templateRef = null;
for (int i = 0; i < vmList.Length; i++)
{
if (vmList.type == "VirtualMachine")
{
Object[] vmProps = getProperties(vmListi], new String[ { "config.name", "config.template" });
if (((String)vmProps[0]).Equals(srcName))
{
templateRef = vmList;
}
}
}
// Define the operation to be performed.
MethodAction ma = new MethodAction();
ma.argument = new MethodActionArgument[1];
ma.name = "PowerOffVM_Task";
DateTime theDate = DateTime.Now;
theDate.AddMinutes(1);
// Define the scheduled task specification.
OnceTaskScheduler dTScheduler = new OnceTaskScheduler();
dTScheduler.runAt = theDate;
dTScheduler.runAtSpecified = true;
dTScheduler.activeTimeSpecified = true;
dTScheduler.activeTime = DateTime.Now;
dTScheduler.expireTime = theDate.AddHours(1);
dTScheduler.expireTimeSpecified = true;
ScheduledTaskSpec tSpec = new ScheduledTaskSpec();
tSpec.description = "Revert to the specified snapshot according to the schedule.";
tSpec.enabled = true;
tSpec.name = "Power Off Virtual Machine";
tSpec.action = ma;
tSpec.scheduler = dTScheduler;
tSpec.notification = Foo@Bar.com;
VS.CreateScheduledTask(_ServiceContent.scheduledTaskManager, templateRef, tSpec);
Error: SOAPEXCEPTION was unhandled. Aspecified parameter was not correct.
Do i am doing wrong with this parameter:--------------------------------------------
ma.argument = new MethodActionArgument[1];
Regards
Sudhir Kumar