public static void Update(PowerShellManager powerShell, VirtualMachine vm, bool bootFromCD, bool numLockEnabled) { // for Win2012R2+ and Win8.1+ if (vm.Generation == 2) { Command cmd = new Command("Set-VMFirmware"); cmd.Parameters.Add("VMName", vm.Name); if (bootFromCD) { cmd.Parameters.Add("FirstBootDevice", DvdDriveHelper.GetPS(powerShell, vm.Name)); } else { cmd.Parameters.Add("FirstBootDevice", HardDriveHelper.GetPS(powerShell, vm.Name).FirstOrDefault()); } powerShell.Execute(cmd, true); } // for others win and linux else { Command cmd = new Command("Set-VMBios"); cmd.Parameters.Add("VMName", vm.Name); var bootOrder = bootFromCD ? new[] { "CD", "IDE", "LegacyNetworkAdapter", "Floppy" } : new[] { "IDE", "CD", "LegacyNetworkAdapter", "Floppy" }; cmd.Parameters.Add("StartupOrder", bootOrder); powerShell.Execute(cmd, true); } }
public static VirtualMachineNetworkAdapter[] Get(PowerShellManager powerShell, string vmName) { List <VirtualMachineNetworkAdapter> adapters = new List <VirtualMachineNetworkAdapter>(); Command cmd = new Command("Get-VMNetworkAdapter"); if (!string.IsNullOrEmpty(vmName)) { cmd.Parameters.Add("VMName", vmName); } Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { foreach (PSObject psAdapter in result) { VirtualMachineNetworkAdapter adapter = new VirtualMachineNetworkAdapter(); adapter.Name = psAdapter.GetString("Name"); adapter.MacAddress = psAdapter.GetString("MacAddress"); adapter.SwitchName = psAdapter.GetString("SwitchName"); adapters.Add(adapter); } } return(adapters.ToArray()); }
public static void SetFirewallRule(PowerShellManager powerShell, bool enabled) { Command cmd = new Command("Enable-Netfirewallrule"); cmd.Parameters.Add("DisplayName", "Hyper-V Replica HTTPS Listener (TCP-In)"); powerShell.Execute(cmd, false); }
//public static VirtualHardDiskInfo GetByPath(PowerShellManager powerShell, string vhdPath) //{ // VirtualHardDiskInfo info = null; // var vmNames = new List<string>(); // Command cmd = new Command("Get-VM"); // Collection<PSObject> result = powerShell.Execute(cmd, true); // if (result == null || result.Count == 0) // return null; // vmNames = result.Select(r => r.GetString("Name")).ToList(); // var drives = vmNames.SelectMany(n => Get(powerShell, n)); // return drives.FirstOrDefault(d=>d.Path == vhdPath); //} public static Collection<PSObject> GetPS(PowerShellManager powerShell, string vmname) { Command cmd = new Command("Get-VMHardDiskDrive"); cmd.Parameters.Add("VMName", vmname); return powerShell.Execute(cmd, true); }
public static void SetReplicaServer(PowerShellManager powerShell, bool enabled, string remoteServer, string thumbprint, string storagePath) { Command cmd = new Command("Set-VMReplicationServer"); cmd.Parameters.Add("ReplicationEnabled", enabled); if (!string.IsNullOrEmpty(remoteServer)) { cmd.Parameters.Add("ComputerName", remoteServer); } if (!string.IsNullOrEmpty(thumbprint)) { cmd.Parameters.Add("AllowedAuthenticationType", "Certificate"); cmd.Parameters.Add("CertificateThumbprint", thumbprint); } if (!string.IsNullOrEmpty(storagePath)) { cmd.Parameters.Add("ReplicationAllowedFromAnyServer", true); cmd.Parameters.Add("DefaultStorageLocation", storagePath); } powerShell.Execute(cmd, false); }
public static void RemoveVmReplication(PowerShellManager powerShell, string vmName, string server) { Command cmd = new Command("Remove-VMReplication"); cmd.Parameters.Add("VmName", vmName); if (!string.IsNullOrEmpty(server)) cmd.Parameters.Add("ComputerName", server); powerShell.Execute(cmd, false); }
public static void Add(PowerShellManager powerShell, string vmName) { Command cmd = new Command("Add-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); powerShell.Execute(cmd, true); }
public static void Delete(PowerShellManager powerShell, string vmName, string server) { Command cmd = new Command("Remove-VM"); cmd.Parameters.Add("Name", vmName); if (!string.IsNullOrEmpty(server)) cmd.Parameters.Add("ComputerName", server); cmd.Parameters.Add("Force"); powerShell.Execute(cmd, false, true); }
//public static VirtualHardDiskInfo GetByPath(PowerShellManager powerShell, string vhdPath) //{ // VirtualHardDiskInfo info = null; // var vmNames = new List<string>(); // Command cmd = new Command("Get-VM"); // Collection<PSObject> result = powerShell.Execute(cmd, true); // if (result == null || result.Count == 0) // return null; // vmNames = result.Select(r => r.GetString("Name")).ToList(); // var drives = vmNames.SelectMany(n => Get(powerShell, n)); // return drives.FirstOrDefault(d=>d.Path == vhdPath); //} public static Collection <PSObject> GetPS(PowerShellManager powerShell, string vmname) { Command cmd = new Command("Get-VMHardDiskDrive"); cmd.Parameters.Add("VMName", vmname); return(powerShell.Execute(cmd, true)); }
public static void SetFirewallRule(PowerShellManager powerShell, bool enabled) { Command cmd = new Command("Enable-Netfirewallrule"); cmd.Parameters.Add("DisplayName", "Hyper-V Replica HTTPS Listener (TCP-In)"); powerShell.Execute(cmd, false); }
public static void Add(PowerShellManager powerShell, string vmName) { Command cmd = new Command("Add-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); powerShell.Execute(cmd, true); }
public static void Delete(PowerShellManager powerShell, VirtualMachineSnapshot snapshot, bool includeChilds) { Command cmd = new Command("Remove-VMSnapshot"); cmd.Parameters.Add("VMName", snapshot.VMName); cmd.Parameters.Add("Name", snapshot.Name); if (includeChilds) cmd.Parameters.Add("IncludeAllChildSnapshots", true); powerShell.Execute(cmd, true); }
public static void Delete(PowerShellManager powerShell, string vmName, VirtualMachineNetworkAdapter networkAdapter) { Command cmd = new Command("Remove-VMNetworkAdapter"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("Name", networkAdapter.Name); powerShell.Execute(cmd, true); }
public static void Stop(PowerShellManager powerShell, string vmName, bool force, string server) { Command cmd = new Command("Stop-VM"); cmd.Parameters.Add("Name", vmName); if (force) cmd.Parameters.Add("Force"); if (!string.IsNullOrEmpty(server)) cmd.Parameters.Add("ComputerName", server); //if (!string.IsNullOrEmpty(reason)) cmd.Parameters.Add("Reason", reason); powerShell.Execute(cmd, false); }
public static void RemoveVmReplication(PowerShellManager powerShell, string vmName, string server) { Command cmd = new Command("Remove-VMReplication"); cmd.Parameters.Add("VmName", vmName); if (!string.IsNullOrEmpty(server)) { cmd.Parameters.Add("ComputerName", server); } powerShell.Execute(cmd, false); }
public static void Delete(PowerShellManager powerShell, string vmName, string server) { Command cmd = new Command("Remove-VM"); cmd.Parameters.Add("Name", vmName); if (!string.IsNullOrEmpty(server)) { cmd.Parameters.Add("ComputerName", server); } cmd.Parameters.Add("Force"); powerShell.Execute(cmd, false, true); }
public static void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings) { Command cmd = new Command("Set-VMProcessor"); cmd.Parameters.Add("VMName", vm.Name); cmd.Parameters.Add("Count", cpuCores); cmd.Parameters.Add("Maximum", cpuLimitSettings); cmd.Parameters.Add("Reserve", cpuReserveSettings); cmd.Parameters.Add("RelativeWeight", cpuWeightSettings); powerShell.Execute(cmd, true); }
public static void UpdateProcessors(PowerShellManager powerShell, VirtualMachine vm, int cpuCores, int cpuLimitSettings, int cpuReserveSettings, int cpuWeightSettings) { Command cmd = new Command("Set-VMProcessor"); cmd.Parameters.Add("VMName", vm.Name); cmd.Parameters.Add("Count", cpuCores); cmd.Parameters.Add("Maximum", cpuLimitSettings); cmd.Parameters.Add("Reserve", cpuReserveSettings); cmd.Parameters.Add("RelativeWeight", cpuWeightSettings); powerShell.Execute(cmd, true); }
public static void Remove(PowerShellManager powerShell, string vmName) { var dvd = Get(powerShell, vmName); Command cmd = new Command("Remove-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber); cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation); powerShell.Execute(cmd, true); }
public static void Set(PowerShellManager powerShell, string vmName, string path) { var dvd = Get(powerShell, vmName); Command cmd = new Command("Set-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("Path", path); cmd.Parameters.Add("ControllerNumber", dvd.ControllerNumber); cmd.Parameters.Add("ControllerLocation", dvd.ControllerLocation); powerShell.Execute(cmd, true); }
public static void Delete(PowerShellManager powerShell, VirtualMachineSnapshot snapshot, bool includeChilds) { Command cmd = new Command("Remove-VMSnapshot"); cmd.Parameters.Add("VMName", snapshot.VMName); cmd.Parameters.Add("Name", snapshot.Name); if (includeChilds) { cmd.Parameters.Add("IncludeAllChildSnapshots", true); } powerShell.Execute(cmd, true); }
public static PSObject GetPS(PowerShellManager powerShell, string vmName) { Command cmd = new Command("Get-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { return result[0]; } return null; }
public static void Add(PowerShellManager powerShell, string vmName, string switchId, string macAddress, string adapterName, bool legacyAdapter) { Command cmd = new Command("Add-VMNetworkAdapter"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("Name", adapterName); cmd.Parameters.Add("SwitchName", switchId); if (String.IsNullOrEmpty(macAddress)) cmd.Parameters.Add("DynamicMacAddress"); else cmd.Parameters.Add("StaticMacAddress", macAddress); powerShell.Execute(cmd, true); }
public static PSObject GetPS(PowerShellManager powerShell, string vmName) { Command cmd = new Command("Get-VMDvdDrive"); cmd.Parameters.Add("VMName", vmName); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { return(result[0]); } return(null); }
public static int GetVMProcessors(PowerShellManager powerShell, string name) { int procs = 0; Command cmd = new Command("Get-VMProcessor"); cmd.Parameters.Add("VMName", name); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { procs = Convert.ToInt32(result[0].GetProperty("Count")); } return procs; }
public static int GetVMProcessors(PowerShellManager powerShell, string name) { int procs = 0; Command cmd = new Command("Get-VMProcessor"); cmd.Parameters.Add("VMName", name); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { procs = Convert.ToInt32(result[0].GetProperty("Count")); } return(procs); }
public static void Stop(PowerShellManager powerShell, string vmName, bool force, string server) { Command cmd = new Command("Stop-VM"); cmd.Parameters.Add("Name", vmName); if (force) { cmd.Parameters.Add("Force"); } if (!string.IsNullOrEmpty(server)) { cmd.Parameters.Add("ComputerName", server); } //if (!string.IsNullOrEmpty(reason)) cmd.Parameters.Add("Reason", reason); powerShell.Execute(cmd, false); }
public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk) { if (!string.IsNullOrEmpty(path)) { Command cmd = new Command("Get-VHD"); cmd.Parameters.Add("Path", path); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { disk.DiskFormat = result[0].GetEnum <VirtualHardDiskFormat>("VhdFormat"); disk.DiskType = result[0].GetEnum <VirtualHardDiskType>("VhdType"); disk.ParentPath = result[0].GetProperty <string>("ParentPath"); disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size")); disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize")); disk.Attached = disk.InUse = Convert.ToBoolean(result[0].GetProperty("Attached")); } } }
public static void GetVirtualHardDiskDetail(PowerShellManager powerShell, string path, ref VirtualHardDiskInfo disk) { if (!string.IsNullOrEmpty(path)) { Command cmd = new Command("Get-VHD"); cmd.Parameters.Add("Path", path); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { disk.DiskFormat = result[0].GetEnum<VirtualHardDiskFormat>("VhdFormat"); disk.DiskType = result[0].GetEnum<VirtualHardDiskType>("VhdType"); disk.ParentPath = result[0].GetProperty<string>("ParentPath"); disk.MaxInternalSize = Convert.ToInt64(result[0].GetProperty("Size")); disk.FileSize = Convert.ToInt64(result[0].GetProperty("FileSize")); disk.Attached = disk.InUse = Convert.ToBoolean(result[0].GetProperty("Attached")); } } }
public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name) { OperationalStatus status = OperationalStatus.None; Command cmd = new Command("Get-VMIntegrationService"); cmd.Parameters.Add("VMName", name); cmd.Parameters.Add("Name", "HeartBeat"); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { var statusString = result[0].GetProperty("PrimaryOperationalStatus"); if (statusString != null) status = (OperationalStatus)Enum.Parse(typeof(OperationalStatus), statusString.ToString()); } return status; }
public static void Add(PowerShellManager powerShell, string vmName, string switchId, string macAddress, string adapterName, bool legacyAdapter) { Command cmd = new Command("Add-VMNetworkAdapter"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("Name", adapterName); cmd.Parameters.Add("SwitchName", switchId); if (String.IsNullOrEmpty(macAddress)) { cmd.Parameters.Add("DynamicMacAddress"); } else { cmd.Parameters.Add("StaticMacAddress", macAddress); } powerShell.Execute(cmd, true); }
public static DynamicMemory GetDynamicMemory(PowerShellManager powerShell, string vmName) { DynamicMemory info = null; Command cmd = new Command("Get-VMMemory"); cmd.Parameters.Add("VMName", vmName); Collection<PSObject> result = powerShell.Execute(cmd); if (result != null && result.Count > 0) { info = new DynamicMemory(); info.Enabled = result[0].GetBool("DynamicMemoryEnabled"); info.Minimum = Convert.ToInt32(result[0].GetLong("Minimum") / Constants.Size1M); info.Maximum = Convert.ToInt32(result[0].GetLong("Maximum") / Constants.Size1M); info.Buffer = Convert.ToInt32(result[0].GetInt("Buffer")); info.Priority = Convert.ToInt32(result[0].GetInt("Priority")); } return info; }
public static DynamicMemory GetDynamicMemory(PowerShellManager powerShell, string vmName) { DynamicMemory info = null; Command cmd = new Command("Get-VMMemory"); cmd.Parameters.Add("VMName", vmName); Collection <PSObject> result = powerShell.Execute(cmd); if (result != null && result.Count > 0) { info = new DynamicMemory(); info.Enabled = result[0].GetBool("DynamicMemoryEnabled"); info.Minimum = Convert.ToInt32(result[0].GetLong("Minimum") / Constants.Size1M); info.Maximum = Convert.ToInt32(result[0].GetLong("Maximum") / Constants.Size1M); info.Buffer = Convert.ToInt32(result[0].GetInt("Buffer")); info.Priority = Convert.ToInt32(result[0].GetInt("Priority")); } return(info); }
public static OperationalStatus GetVMHeartBeatStatus(PowerShellManager powerShell, string name) { OperationalStatus status = OperationalStatus.None; Command cmd = new Command("Get-VMIntegrationService"); cmd.Parameters.Add("VMName", name); cmd.Parameters.Add("Name", "HeartBeat"); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { var statusString = result[0].GetProperty("PrimaryOperationalStatus"); if (statusString != null) { status = (OperationalStatus)Enum.Parse(typeof(OperationalStatus), statusString.ToString()); } } return(status); }
public static void Update(PowerShellManager powerShell, VirtualMachine vm, int ramMb, DynamicMemory dynamicMemory) { Command cmd = new Command("Set-VMMemory"); cmd.Parameters.Add("VMName", vm.Name); cmd.Parameters.Add("StartupBytes", ramMb * Constants.Size1M); if (dynamicMemory != null && dynamicMemory.Enabled) { cmd.Parameters.Add("DynamicMemoryEnabled", true); cmd.Parameters.Add("MinimumBytes", dynamicMemory.Minimum * Constants.Size1M); cmd.Parameters.Add("MaximumBytes", dynamicMemory.Maximum * Constants.Size1M); cmd.Parameters.Add("Buffer", dynamicMemory.Buffer); cmd.Parameters.Add("Priority", dynamicMemory.Priority); } else { cmd.Parameters.Add("DynamicMemoryEnabled", false); } powerShell.Execute(cmd, true, true); }
public static void Update(PowerShellManager powerShell, VirtualMachine vm, int ramMb, DynamicMemory dynamicMemory) { Command cmd = new Command("Set-VMMemory"); cmd.Parameters.Add("VMName", vm.Name); cmd.Parameters.Add("StartupBytes", ramMb * Constants.Size1M); if (dynamicMemory != null && dynamicMemory.Enabled) { cmd.Parameters.Add("DynamicMemoryEnabled", true); cmd.Parameters.Add("MinimumBytes", dynamicMemory.Minimum * Constants.Size1M); cmd.Parameters.Add("MaximumBytes", dynamicMemory.Maximum * Constants.Size1M); cmd.Parameters.Add("Buffer", dynamicMemory.Buffer); cmd.Parameters.Add("Priority", dynamicMemory.Priority); } else { cmd.Parameters.Add("DynamicMemoryEnabled", false); } powerShell.Execute(cmd, true, true); }
public static VirtualMachineNetworkAdapter[] Get(PowerShellManager powerShell, string vmName) { List<VirtualMachineNetworkAdapter> adapters = new List<VirtualMachineNetworkAdapter>(); Command cmd = new Command("Get-VMNetworkAdapter"); if (!string.IsNullOrEmpty(vmName)) cmd.Parameters.Add("VMName", vmName); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { foreach (PSObject psAdapter in result) { VirtualMachineNetworkAdapter adapter = new VirtualMachineNetworkAdapter(); adapter.Name = psAdapter.GetString("Name"); adapter.MacAddress = psAdapter.GetString("MacAddress"); adapter.SwitchName = psAdapter.GetString("SwitchName"); adapters.Add(adapter); } } return adapters.ToArray(); }
public static void SetReplicaServer(PowerShellManager powerShell, bool enabled, string remoteServer, string thumbprint, string storagePath) { Command cmd = new Command("Set-VMReplicationServer"); cmd.Parameters.Add("ReplicationEnabled", enabled); if (!string.IsNullOrEmpty(remoteServer)) { cmd.Parameters.Add("ComputerName", remoteServer); } if (!string.IsNullOrEmpty(thumbprint)) { cmd.Parameters.Add("AllowedAuthenticationType", "Certificate"); cmd.Parameters.Add("CertificateThumbprint", thumbprint); } if (!string.IsNullOrEmpty(storagePath)) { cmd.Parameters.Add("ReplicationAllowedFromAnyServer", true); cmd.Parameters.Add("DefaultStorageLocation", storagePath); } powerShell.Execute(cmd, false); }
public static BiosInfo Get(PowerShellManager powerShell, string name, int generation) { BiosInfo info = new BiosInfo(); // for Win2012R2+ and Win8.1+ if (generation == 2) { Command cmd = new Command("Get-VMFirmware"); cmd.Parameters.Add("VMName", name); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { info.NumLockEnabled = true; List <string> startupOrders = new List <string>(); info.BootFromCD = false; foreach (dynamic item in (IEnumerable)result[0].GetProperty("BootOrder")) { string bootType = item.BootType.ToString(); // bootFromCD if (!startupOrders.Any() && bootType == "Drive") { var device = item.Device; info.BootFromCD = device.GetType().Name == "DvdDrive"; } // startupOrders startupOrders.Add(bootType); } info.StartupOrder = startupOrders.ToArray(); } } // for others win and linux else { Command cmd = new Command("Get-VMBios"); cmd.Parameters.Add("VMName", name); Collection <PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { info.NumLockEnabled = Convert.ToBoolean(result[0].GetProperty("NumLockEnabled")); List <string> startupOrders = new List <string>(); foreach (var item in (IEnumerable)result[0].GetProperty("StartupOrder")) { startupOrders.Add(item.ToString()); } info.StartupOrder = startupOrders.ToArray(); info.BootFromCD = false; if (info.StartupOrder != null && info.StartupOrder.Length > 0) { info.BootFromCD = info.StartupOrder[0] == "CD"; } } } return(info); }
public static void UpdateIOPS(PowerShellManager powerShell, VirtualMachine vm, int IOPSmin, int IOPSmax) { if (vm.Disks != null && (IOPSmax >= IOPSmin)) { foreach (VirtualHardDiskInfo d in vm.Disks) { Command cmd = new Command("Set-VMHardDiskDrive"); cmd.Parameters.Add("VMName", vm.Name); cmd.Parameters.Add("ControllerType", d.VHDControllerType.ToString()); cmd.Parameters.Add("ControllerNumber", d.ControllerNumber); cmd.Parameters.Add("ControllerLocation", d.ControllerLocation); if (IOPSmin == IOPSmax) //disable QoS control { cmd.Parameters.Add("MinimumIOPS", false); cmd.Parameters.Add("MaximumIOPS", false); } else { cmd.Parameters.Add("MinimumIOPS", IOPSmin); cmd.Parameters.Add("MaximumIOPS", IOPSmax); } powerShell.Execute(cmd, true, true); } } }
public static BiosInfo Get(PowerShellManager powerShell, string name, int generation) { BiosInfo info = new BiosInfo(); // for Win2012R2+ and Win8.1+ if (generation == 2) { Command cmd = new Command("Get-VMFirmware"); cmd.Parameters.Add("VMName", name); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { info.NumLockEnabled = true; List<string> startupOrders = new List<string>(); info.BootFromCD = false; foreach (dynamic item in (IEnumerable)result[0].GetProperty("BootOrder")) { string bootType = item.BootType.ToString(); // bootFromCD if (!startupOrders.Any() && bootType == "Drive") { var device = item.Device; info.BootFromCD = device.GetType().Name == "DvdDrive"; } // startupOrders startupOrders.Add(bootType); } info.StartupOrder = startupOrders.ToArray(); } } // for others win and linux else { Command cmd = new Command("Get-VMBios"); cmd.Parameters.Add("VMName", name); Collection<PSObject> result = powerShell.Execute(cmd, true); if (result != null && result.Count > 0) { info.NumLockEnabled = Convert.ToBoolean(result[0].GetProperty("NumLockEnabled")); List<string> startupOrders = new List<string>(); foreach (var item in (IEnumerable)result[0].GetProperty("StartupOrder")) startupOrders.Add(item.ToString()); info.StartupOrder = startupOrders.ToArray(); info.BootFromCD = false; if (info.StartupOrder != null && info.StartupOrder.Length > 0) info.BootFromCD = info.StartupOrder[0] == "CD"; } } return info; }
public static void Delete(PowerShellManager powerShell, string vmName, VirtualMachineNetworkAdapter networkAdapter) { Command cmd = new Command("Remove-VMNetworkAdapter"); cmd.Parameters.Add("VMName", vmName); cmd.Parameters.Add("Name", networkAdapter.Name); powerShell.Execute(cmd, true); }
public static void Update(PowerShellManager powerShell, VirtualMachine vm, bool bootFromCD, bool numLockEnabled) { // for Win2012R2+ and Win8.1+ if (vm.Generation == 2) { Command cmd = new Command("Set-VMFirmware"); cmd.Parameters.Add("VMName", vm.Name); if (bootFromCD) cmd.Parameters.Add("FirstBootDevice", DvdDriveHelper.GetPS(powerShell, vm.Name)); else cmd.Parameters.Add("FirstBootDevice", HardDriveHelper.GetPS(powerShell, vm.Name).FirstOrDefault()); powerShell.Execute(cmd, true); } // for others win and linux else { Command cmd = new Command("Set-VMBios"); cmd.Parameters.Add("VMName", vm.Name); var bootOrder = bootFromCD ? new[] { "CD", "IDE", "LegacyNetworkAdapter", "Floppy" } : new[] { "IDE", "CD", "LegacyNetworkAdapter", "Floppy" }; cmd.Parameters.Add("StartupOrder", bootOrder); powerShell.Execute(cmd, true); } }