title: Resolving the WMI DNS Host Name
body: <p>I am trying to make a comparison between a machine name i have retrieved from AD, and the DNS Host Name i want to get using WMI from the machine.</p>
  
  <p>I currently have:</p>
  
  <pre><code>foreach (SearchResult oneMachine in allMachinesCollected)
              {
                  pcName = oneMachine.Properties["name"][0].ToString();
                  ConnectionOptions setupConnection = new ConnectionOptions();
                  setupConnection.Username = USERNAME;
                  setupConnection.Password = PASSWORD;
                  setupConnection.Authority = "ntlmdomain:DOMAIN";
                  ManagementScope setupScope = new ManagementScope("\\\\" + pcName + "\\root\\cimv2", setupConnection);
                  setupScope.Connect();
  
                  ObjectQuery dnsNameQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
                  ManagementObjectSearcher dnsNameSearch = new ManagementObjectSearcher(setupScope, dnsNameQuery);
                  ManagementObjectCollection allDNSNames = dnsNameSearch.Get();
                  string dnsHostName;
                  foreach (ManagementObject oneName in allDNSNames)
                  {
                      dnsHostName = oneName.Properties["DNSHostName"].ToString();
                      if (dnsHostName == pcName)
                      {
                          shutdownMethods.ShutdownMachine(pcName, USERNAME, PASSWORD);
                          MessageBox.Show(pcName + " has been sent the reboot command");
                      }
                  }
              }
          }
  </code></pre>
  
  <p>But i get a ManagementException >> dnsHostName = oneName.Properties["DNSHostName"].ToString(); &lt;&lt; here saying not found.
  Any ideas?</p>