title: Managing a windows cluster from C#
body: <p>I am trying to start/stop a windows based cluster in C#, below is the code I am working with so far...when I get to TakeOffLine function below I get a "Not Found" exception from, System.Management.ManagementStatus.NotFound. Not sure what is exactly not being found? If there is a (alternate) better way of doing this please let me know.</p>
  
  <p>Thanks!</p>
  
  <pre><code>using System.Management;
  class App
  {
      public static void Main()
      {
          string clusterName = "clusterHex";    // cluster alias
          string custerGroupResource = "clusterHex.internal.com"; // Cluster group name
  
          ConnectionOptions options = new ConnectionOptions();
          options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;
  
          // Connect with the mscluster WMI namespace on the cluster named "MyCluster"
          ManagementScope s = new ManagementScope("\\\\" + clusterName +
              "\\root\\mscluster", options);
  
          ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
  
          using (ManagementObject clrg = new ManagementObject(s, p, null))
          {
              // Take clustergroup off line and read its status property when done
              TakeOffLine(clrg);
              clrg.Get();
              Console.WriteLine(clrg["Status"]);
              System.Threading.Thread.Sleep(3000);    // Sleep for a while
              // Bring back online  and get status.
              BringOnLine(clrg);
              clrg.Get();
              Console.WriteLine(clrg["Status"]);
  
          }
      }
      static void TakeOffLine(ManagementObject resourceGroup)
      {
          ManagementBaseObject outParams =
          resourceGroup.InvokeMethod("Takeoffline", null, null);
      }
      static void BringOnLine(ManagementObject resourceGroup)
      {
          ManagementBaseObject outParams =
          resourceGroup.InvokeMethod("Takeoffline", null, null);
      }
  }
  </code></pre>