public static void gethostadapters(string[] tokens) { string server = Dns.GetHostName(); if (tokens.Length == 2) { server = tokens[1]; } var adapters = NetAdapter.GetNetAdapter(server); PrintRow(new string[] { "Name", "InterfaceDescription", "MacAddress", "Status" }); PrintLine(); foreach (var obj in adapters) { PrintRow(new string[] { (string)obj.Members["Name"].Value, (string)obj.Members["InterfaceDescription"].Value, (string)obj.Members["MacAddress"].Value, (string)obj.Members["ifOperStatus"].Value }); } Console.WriteLine(); foreach (var obj in adapters) { Console.WriteLine(obj); } }
public static void newvmswitch(string[] tokens) { string server = Dns.GetHostName(); if (tokens.Length == 2) { server = tokens[1]; } Console.Write("Name: "); string name = Console.ReadLine(); Console.WriteLine("Choose an adapter:"); var adapters = NetAdapter.GetNetAdapter(server); for (int i = 0; i < adapters.Count; i++) { Console.WriteLine($"[{i}] ({ adapters[i].Members["Name"].Value }) { adapters[i].Members["InterfaceDescription"].Value }"); } var ada = adapters[GetSelectedIndex()].Members["InterfaceDescription"].Value.ToString(); PSWrapper.Execute(server, (ps) => { return(ps.AddCommand("New-VMSwitch") .AddParameter("Name", name) .AddParameter("NetAdapterInterfaceDescription", ada) .AddParameter("AllowManagementOS", true) .Invoke()); }, PsStreamEventHandlers.DefaultHandlers); }