Пример #1
0
        public static void TestPreLoadVHDBootData()
        {
            try
            {
                Console.WriteLine("Starting - PreLoadVHDBootData");

                // instantiate a PowerShell Interfae Object
                //
                VMFactory.Api.HyperV.PsInterface psi = new PsInterface();

                // create the list of parameters to add to the PS execution in the format NAME/VALUE pairs
                Dictionary <String, String> parameters = new Dictionary <string, string>();
                parameters.Add("vhdPath", "d:\\_VMs\\SP2013\\PTMoss2k13.vhd");
                parameters.Add("driveLetter", "x:");
                parameters.Add("dismPath", "C:\\Windows\\System32\\");
                parameters.Add("vmName", "MyTestVm");
                parameters.Add("vmId", "{6172815E-4839-4C80-A55E-DE4DEF52C54B}");
                parameters.Add("vmStatusSvcUrl", "http://yadayada");
                parameters.Add("cfgFileName", "VMFConfigTest.xml");

                // define the type of operation. This is an enumeration and can/shuld be extended as needed
                psi.Command = PsOperation.PreLoadVHDBootData;

                // set the VM Name
                psi.VmName = "MyTestVm";

                // set the PS Command Parameters
                //psi.Parameters = parameters;

                PsExecutionResult result = psi.Execute();

                // test command execution result
                if (result.Success)
                {
                    Console.WriteLine("Success!!");

                    // print the command output
                    Console.WriteLine(result.ResultMessage);
                }
                else
                {
                    Console.WriteLine(result.ResultMessage);

                    // Access the exception data
                    Console.WriteLine(result.Exception.Message);
                    Console.WriteLine(result.Exception.StackTrace);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace));
            }
            finally
            {
                Console.WriteLine("Finished. Press ENTER to exit");
                Console.ReadLine();
            }
        }
Пример #2
0
        public static void TestVMCopyAndImportVM()
        {
            try
            {
                Console.WriteLine("Starting - VMCopyAndImportVM");

                // instantiate a PowerShell Interfae Object
                //
                VMFactory.Api.HyperV.PsInterface psi = new PsInterface();

                // create the list of parameters to add to the PS execution in the format NAME/VALUE pairs
                Dictionary <String, object> parameters = new Dictionary <string, object>();

                parameters.Add("Source", "D:\\_VMs\\base");
                parameters.Add("Destination", "D:\\_VMs\\NewTest\\");
                parameters.Add("VMPath", "D:\\_VMs\\base\\VMFTestBoot\\Virtual Machines\\2E4588A4-A37A-4A33-ABA7-E7A9A7C1D8F2.xml");
                parameters.Add("vmName", "MyTestVm");
                parameters.Add("VMBaseName", "BASE_VMF_VM");

                // define the type of operation. This is an enumeration and can/shuld be extended as needed
                psi.Command = PsOperation.VMCopyAndImport;

                // set the VM Name
                psi.VmName = "MyTestVm";

                // set the PS Command Parameters
                psi.Parameters = parameters;

                PsExecutionResult result = psi.Execute();

                // test command execution result
                if (result.Success)
                {
                    Console.WriteLine("Success!!");

                    // print the command output
                    Console.WriteLine(result.ResultMessage);
                }
                else
                {
                    Console.WriteLine(result.ResultMessage);

                    // Access the exception data
                    Console.WriteLine(result.Exception.Message);
                    Console.WriteLine(result.Exception.StackTrace);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace));
            }
            finally
            {
                Console.WriteLine("Finished. Press ENTER to exit");
                Console.ReadLine();
            }
        }
Пример #3
0
        public static PsExecutionResult StartVM(string vmName)
        {
            PsExecutionResult result = null;

            try
            {
                Console.WriteLine("Starting - StartVM");

                // instantiate a PowerShell Interfae Object
                //
                VMFactory.Api.HyperV.PsInterface psi = new PsInterface();

                // create the list of parameters to add to the PS execution in the format NAME/VALUE pairs
                Dictionary <String, object> parameters = new Dictionary <string, object>();

                parameters.Add("vmName", vmName);

                // define the type of operation. This is an enumeration and can/shuld be extended as needed
                psi.Command = PsOperation.StartVm;

                // set the VM Name
                //psi.VmName = "MyTestVm";

                // set the PS Command Parameters
                psi.Parameters = parameters;

                result = psi.Execute();

                // test command execution result
                if (result.Success)
                {
                    Console.WriteLine("Success!!");

                    // print the command output
                    Console.WriteLine(result.ResultMessage);
                }
                else
                {
                    Console.WriteLine(result.ResultMessage);

                    // Access the exception data
                    Console.WriteLine(result.Exception.Message);
                    Console.WriteLine(result.Exception.StackTrace);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace));
            }
            finally
            {
                Console.WriteLine("Finished. Press ENTER to exit");
                Console.ReadLine();
            }
            return(result);
        }
Пример #4
0
 /// <summary>
 /// Copies the and import vm.
 /// </summary>
 /// <param name="baseVmName">Name of the base vm.</param>
 /// <param name="baseVmSourcePath">The base vm source path.</param>
 /// <param name="destinationFolder">The destination folder.</param>
 /// <param name="baseVmConfigFile">The base vm configuration file.</param>
 /// <param name="newVmName">New name of the vm.</param>
 public static void CopyAndImportVM(string baseVmName, string baseVmSourcePath, string destinationFolder, string baseVmConfigFile, string newVmName)
 {
     try { Console.WriteLine("Starting - VMCopyAndImportVM"); VMFactory.Api.HyperV.PsInterface psi = new PsInterface(); Dictionary <String, object> parameters = new Dictionary <string, object>();  parameters.Add("Source", baseVmSourcePath); parameters.Add("Destination", destinationFolder); parameters.Add("VMPath", baseVmConfigFile); parameters.Add("vmName", newVmName); parameters.Add("VMBaseName", baseVmName);  psi.Command = PsOperation.VMCopyAndImport; psi.VmName = "MyTestVm"; psi.Parameters = parameters;  PsExecutionResult result = psi.Execute();                 if (result.Success)
           {
               Console.WriteLine("Success!!"); Console.WriteLine(result.ResultMessage);
           }
           else
           {
               Console.WriteLine(result.ResultMessage); Console.WriteLine(result.Exception.Message); Console.WriteLine(result.Exception.StackTrace);
           } } catch (Exception e) { Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace)); } finally { if (DefaultConfigurationStore.Current.RequestUserConfirmation)
                                                                                                                        {
                                                                                                                            Console.WriteLine("Finished. Press ENTER to exit"); Console.ReadLine();
                                                                                                                        }
     }
 }
Пример #5
0
 /// <summary>
 /// Stops the vm.
 /// </summary>
 /// <param name="vmName">Name of the vm.</param>
 /// <returns></returns>
 public static bool RemoveVM(string vmName = null)
 {
     bool tResult = false;  try { Console.WriteLine("Starting - RemoveVM"); VMFactory.Api.HyperV.PsInterface psi = new PsInterface();  Dictionary <String, object> parameters = new Dictionary <string, object>();   parameters.Add("vmName", vmName); psi.Command = PsOperation.RemoveVm; psi.Parameters = parameters;  PsExecutionResult result = psi.Execute(); if (result.Success)
                                  {
                                      Console.WriteLine("Success!!"); Console.WriteLine(result.ResultMessage);
                                  }
                                  else
                                  {
                                      Console.WriteLine(result.ResultMessage); Console.WriteLine(result.Exception.Message); Console.WriteLine(result.Exception.StackTrace);
                                  }  tResult = true; } catch (Exception e) { Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace));  tResult = false; } finally { if (DefaultConfigurationStore.Current.RequestUserConfirmation)
                                                                                                                                                                                  {
                                                                                                                                                                                      Console.WriteLine("Finished. Press ENTER to exit"); Console.ReadLine();
                                                                                                                                                                                  }
     } return(tResult);
 }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="driveLetter"></param>
 /// <param name="dismPath"></param>
 /// <param name="vmName"></param>
 /// <param name="vmId"></param>
 /// <param name="vmStatusSvcUrl"></param>
 /// <param name="cfgFileName"></param>
 /// <returns></returns>
 public static bool PreLoadVHDBootData(string driveLetter, string dismPath, string vmName, string vmId, string vmStatusSvcUrl, string cfgFileName)
 {
     bool tResult = false;  try { Console.WriteLine("Starting - PreLoadVHDBootData"); VMFactory.Api.HyperV.PsInterface psi = new PsInterface(); Dictionary <String, object> parameters = new Dictionary <string, object>();  parameters.Add("driveLetter", driveLetter); parameters.Add("dismPath", dismPath); parameters.Add("vmName", vmName); parameters.Add("vmId", vmId); parameters.Add("vmStatusSvcUrl", vmStatusSvcUrl); parameters.Add("cfgFileName", cfgFileName); psi.Command = PsOperation.PreLoadVHDBootData; psi.Parameters = parameters;  PsExecutionResult result = psi.Execute(); if (result.Success)
                                  {
                                      Console.WriteLine("Success!!"); Console.WriteLine(result.ResultMessage);
                                  }
                                  else
                                  {
                                      Console.WriteLine(result.ResultMessage); Console.WriteLine(result.Exception.Message); Console.WriteLine(result.Exception.StackTrace);
                                  } tResult = true; }             catch (Exception e) { Console.WriteLine(String.Format("{0}\n{1}", e.Message, e.StackTrace));  tResult = false; } finally { if (DefaultConfigurationStore.Current.RequestUserConfirmation)
                                                                                                                                                                                             {
                                                                                                                                                                                                 Console.WriteLine("Finished. Press ENTER to exit"); Console.ReadLine();
                                                                                                                                                                                             }
     }              return(tResult);
 }