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 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); }