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.
Thanks!
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);
}
}
Microsoft Failover Cluster Manager (MSFCM) is a specific management function within the Windows Server operating system which is used to create, validate, and manage failover server clusters running Windows Server.
Looks like you're missing case in your method call. You have to use TakeOffline
according to msdn
static void TakeOffLine(ManagementObject resourceGroup)
{
ManagementBaseObject outParams =
resourceGroup.InvokeMethod("TakeOffline", null, null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With