public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > RecreateOrReload(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine)
 {
     return(Prelude.Try(vmInfo.Recreate().Apply(
                            r => Prelude.RightAsync <PowershellFailure, TypedPsObject <VirtualMachineInfo> >(r).ToEither()))
            .MatchAsync(
                Fail: f => vmInfo.Reload(engine),
                Succ: s => s));
 }
        public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > StopIfRunning(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine)
        {
            if (vmInfo.Value.State == VirtualMachineState.Running ||
                vmInfo.Value.State == VirtualMachineState.RunningCritical)
            {
                return(engine.RunAsync(new PsCommandBuilder().AddCommand("Stop-VM").AddParameter("VM", vmInfo.PsObject)
                                       .AddParameter("Force")).MapAsync(u => vmInfo.Recreate()));
            }

            return(Prelude.Right <PowershellFailure, TypedPsObject <VirtualMachineInfo> >(vmInfo).AsTask());
        }
 protected override Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > HandleCommand(TypedPsObject <VirtualMachineInfo> vmInfo, T command, IPowershellEngine engine) =>
 engine.RunAsync(new PsCommandBuilder().AddCommand(TransitionPowerShellCommand).AddParameter("VM", vmInfo.PsObject))
 .MapAsync(u => vmInfo.Recreate());