AddFeatureSettings( string switchName) { ManagementScope scope = new ManagementScope(@"root\virtualization\v2"); string featureId = NetworkingUtilities.GetSwitchFeatureId(NetworkingUtilities.SwitchFeatureType.Bandwidth); using (ManagementObject managementService = NetworkingUtilities.GetEthernetSwitchManagementService(scope)) // // Find the specified switch. // using (ManagementObject ethernetSwitch = NetworkingUtilities.FindEthernetSwitch(switchName, scope)) using (ManagementObject ethernetSwitchSetting = WmiUtilities.GetFirstObjectFromCollection( ethernetSwitch.GetRelated("Msvm_VirtualEthernetSwitchSettingData", "Msvm_SettingsDefineState", null, null, null, null, false, null))) // // Add a new bandwidth setting instance. // using (ManagementObject bandwidthSetting = NetworkingUtilities.GetDefaultFeatureSetting(featureId, scope)) { // // Set the default bandwidth reservation to 10 Mbps. // bandwidthSetting["DefaultFlowReservation"] = 12500000; // in bytes/sec using (ManagementBaseObject inParams = managementService.GetMethodParameters("AddFeatureSettings")) { inParams["AffectedConfiguration"] = ethernetSwitchSetting.Path.Path; inParams["FeatureSettings"] = new string[] { bandwidthSetting.GetText(TextFormat.WmiDtd20) }; using (ManagementBaseObject outParams = managementService.InvokeMethod("AddFeatureSettings", inParams, null)) { WmiUtilities.ValidateOutput(outParams, scope); } } } Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Successfully added bandwidth feature setting to virtual switch '{0}'.", switchName)); }