title: Using System.Management to Query a VMware Server
body: <p>Summary: is it possible to specify a port to use when querying WMI using <code>System.Management;</code></p>
  
  <p>I have a python script under Linux that queries, using WBEM, classes on a number of ESXi servers to check for warnings or errors on various subsystems.  Previously, separately, I have written a WPF application that queries a number of WinTel boxes for their disk consumption etc. using WMI.</p>
  
  <p>I am wanting to write a new WPF application that will perform the same function as the script and I thought I would be able to do this with WMI. Below is my testing code with the error handling removed for brevity, <code>SetOptions</code> is a private function that provides the username and password:</p>
  
  <pre><code> foreach (string hostname in Properties.Settings.Default.Hosts)
       foreach (string WMIclass in Properties.Settings.Default.Classes)
       {
       ObjectQuery Query = new ObjectQuery("SELECT * FROM " + WMIclass);
       ManagementObjectSearcher mos = GetMos(Query, hostname);
       foreach (ManagementObject mo in mos.Get())
           foreach (PropertyData pdc in mo.Properties)
               Debug.WriteLine(pdc.Name + " \t\t: " + pdc.Value);
       }
  
  private ManagementObjectSearcher GetMos(ObjectQuery Query, string Hostname)
  {
       ConnectionOptions Options = SetOptions();
       ManagementScope Scope = new ManagementScope("\\\\" + Hostname + "\\root\\cimv2", Options);
       return new ManagementObjectSearcher(Scope, Query);
  }
  </code></pre>
  
  <p>The trouble is I get a RPC unavailable on the remote server.  I think that is because I am first trying to establish a RPC call on 135 which is not hosted by an ESX server.   My question is how can one specify the port 5989 or is there something straightforward I can use in .net to perform what I need to do.  Naively I'm thinking the class structure looks the same between WMI/WBEM surely it can be done :-/</p>