/**
         * Create a Scheduled Task using the poweroff method action and
         * the onetime scheduler, for the VM found.
         *
         * @param taskAction action to be performed when schedule executes
         * @param scheduler the scheduler used to execute the action
         * @
         */


        private void createScheduledTask(Vim25Api.Action taskAction,
                                         TaskScheduler scheduler)
        {
            try {
                // Create the Scheduled Task Spec and set a unique task name
                // and description, and enable the task as soon as it is created
                String            taskName     = cb.get_option("taskname");
                ScheduledTaskSpec scheduleSpec = new ScheduledTaskSpec();
                scheduleSpec.name        = taskName;
                scheduleSpec.description = "PowerOff VM in 30 minutes";
                scheduleSpec.enabled     = true;

                // Set the PowerOff Method Task Action and the
                // Once scheduler in the spec
                scheduleSpec.action    = taskAction;
                scheduleSpec.scheduler = scheduler;

                // Create ScheduledTask for the VirtualMachine we found earlier
                if (_virtualMachine != null)
                {
                    ManagedObjectReference task =
                        _service.CreateScheduledTask(
                            _scheduleManager, _virtualMachine, scheduleSpec);
                    // printout the MoRef id of the Scheduled Task
                    Console.WriteLine("Successfully created Once Task: "
                                      + taskName);
                }
                else
                {
                    Console.WriteLine("Virtual Machine " + cb.get_option("vmname")
                                      + " not found");
                    return;
                }
            }
            catch (SoapException e)
            {
                if (e.Detail.FirstChild.LocalName.Equals("InvalidRequestFault"))
                {
                    Console.WriteLine(" InvalidRequest: VMname may be wrong");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("DuplicateNameFault"))
                {
                    Console.WriteLine("Error :Task Name already Exists");
                }
            }

            catch (Exception e) {
                Console.WriteLine("Error");
                e.StackTrace.ToString();
            }
        }
        /**
         * Create a Scheduled Task using the reboot method action and
         * the weekly scheduler, for the VM found.
         *
         * @param taskAction action to be performed when schedule executes
         * @param scheduler the scheduler used to execute the action
         * @
         */
        private void createScheduledTask(Vim25Api.Action taskAction,
                                         TaskScheduler scheduler)
        {
            try
            {
                // Create the Scheduled Task Spec and set a unique task name
                // and description, and enable the task as soon as it is created
                String            taskName     = cb.get_option("taskname");
                ScheduledTaskSpec scheduleSpec = new ScheduledTaskSpec();
                scheduleSpec.name        = taskName;
                scheduleSpec.description = "Reboot VM's Guest at 11.59pm every Saturday";
                scheduleSpec.enabled     = true;

                // Set the RebootGuest Method Task action and
                // the Weekly scheduler in the spec
                scheduleSpec.action    = taskAction;
                scheduleSpec.scheduler = scheduler;

                // Create the ScheduledTask for the VirtualMachine we found earlier
                ManagedObjectReference task =
                    _service.CreateScheduledTask(
                        _scheduleManager, _virtualMachine, scheduleSpec);

                // printout the MoRef id of the Scheduled Task
                Console.WriteLine("Successfully created Weekly Task: " +
                                  taskName);
            }
            catch (SoapException e)
            {
                if (e.Detail.FirstChild.LocalName.Equals("InvalidRequestFault"))
                {
                    Console.WriteLine(" InvalidRequest: vmPath may be wrong");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("DuplicateNameFault"))
                {
                    Console.WriteLine("Task Name already Exists");
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Error");
                e.StackTrace.ToString();
            }
        }