MSCluster_service using c# RRS feed

  • Question

  • I have Windows Failover Cluster deployed with 1 or more clusters and services or storage associated with it.

    I am looking for some C# examples of how to report on the above.  I am trying to report on the Cluster Name, the 

    Server Names on the cluster, Services associated with the cluster and storage nodes associated with the cluster.  

    Are there any useful examples that I can refer to?  

    Thank you.

    Friday, September 7, 2018 2:08 PM

All replies

  • Hi NMist,

    >>Are there any useful examples that I can refer to?  

    Please refer to the following code, which use WMI.

    #Caption property of MSCluster_Service

    //Project -> Add reference -> System.Management
    	//using System.Management;
    	//create a management scope object
    	ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\MSCluster");
    	//create object query
    	ObjectQuery query = new ObjectQuery("SELECT * FROM MSCluster_Service Where Name=\"Cluster Service\"SystemName=\"W2012SDC\"");
    	//create object searcher
    	ManagementObjectSearcher searcher =
    	                        new ManagementObjectSearcher(scope, query);
    	//get a collection of WMI objects
    	ManagementObjectCollection queryCollection = searcher.Get();
    	//enumerate the collection.
    	foreach (ManagementObject m in queryCollection) 
    	  // access properties of the WMI object
    	  Console.WriteLine("Caption : {0}", m["Caption"]);

    #WMI query - list of class instances

    //Project -> Add reference -> System.Management
    	//using System.Management;
    	//set the class name and namespace
    	string NamespacePath = "\\\\.\\ROOT\\MSCluster";
    	string ClassName = "MSCluster_Service";
    	//Create ManagementClass
    	ManagementClass oClass = new ManagementClass(NamespacePath + ":" + ClassName);
    	//Get all instances of the class and enumerate them
    	foreach (ManagementObject oObject in oClass.GetInstances())
    		//access a property of the Management object
    		Console.WriteLine("Caption : {0}", oObject["Caption"]);

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, September 10, 2018 1:56 AM