public static IEmulatedEthernetPortSettingData GetDefaultFromResourcePool(IResourcePool resource)
        {
            ManagementObject managementObject = (ManagementObject)null;

            using (ManagementObjectCollection related = ((IWMICommon)resource).Object.GetRelated("Msvm_AllocationCapabilities", "Msvm_ElementCapabilities", (string)null, (string)null, (string)null, (string)null, false, (EnumerationOptions)null))
            {
                using (ManagementObject firstElement = related.GetFirstElement())
                {
                    foreach (ManagementObject relationship in firstElement.GetRelationships("Msvm_SettingsDefineCapabilities"))
                    {
                        if ((int)(ushort)relationship["ValueRole"] == 0)
                        {
                            managementObject = relationship;
                            break;
                        }
                        relationship.Dispose();
                    }
                }
            }
            if (managementObject == null)
            {
                throw new HyperVException("Unable to find the default settings for the resource");
            }
            string path = (string)managementObject["PartComponent"];

            managementObject.Dispose();
            ManagementObject instance = new ManagementObject(path);

            instance.Scope = ((IWMICommon)resource).Scope;
            instance.Get();
            return((IEmulatedEthernetPortSettingData) new EmulatedEthernetPortSettingData(instance));
        }
 public static ManagementObject QueryFirst(this ManagementScope scope, string query)
 {
     using (ManagementObjectCollection moc = scope.Query(query))
         return(moc.GetFirstElement());
 }