How to set cluster resource “Use Network Name for computer name” checkbox programmatically?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am programmatically setting up a cluster resource (specifically, a Generic Service), using the Windows MI API (Microsoft.Management.Infrastructure).



I can add the service resource just fine. However, my service requires the "Use Network Name for computer name" checkbox to be checked (this is available in the Cluster Manager UI by looking at the Properties for the resource).



I can't figure out how to set this using the MI API. I have searched MSDN and multiple other resources for this without luck. Does anybody know if this is possible? Scripting with Powershell would be fine as well.










share|improve this question




























    0















    I am programmatically setting up a cluster resource (specifically, a Generic Service), using the Windows MI API (Microsoft.Management.Infrastructure).



    I can add the service resource just fine. However, my service requires the "Use Network Name for computer name" checkbox to be checked (this is available in the Cluster Manager UI by looking at the Properties for the resource).



    I can't figure out how to set this using the MI API. I have searched MSDN and multiple other resources for this without luck. Does anybody know if this is possible? Scripting with Powershell would be fine as well.










    share|improve this question
























      0












      0








      0








      I am programmatically setting up a cluster resource (specifically, a Generic Service), using the Windows MI API (Microsoft.Management.Infrastructure).



      I can add the service resource just fine. However, my service requires the "Use Network Name for computer name" checkbox to be checked (this is available in the Cluster Manager UI by looking at the Properties for the resource).



      I can't figure out how to set this using the MI API. I have searched MSDN and multiple other resources for this without luck. Does anybody know if this is possible? Scripting with Powershell would be fine as well.










      share|improve this question














      I am programmatically setting up a cluster resource (specifically, a Generic Service), using the Windows MI API (Microsoft.Management.Infrastructure).



      I can add the service resource just fine. However, my service requires the "Use Network Name for computer name" checkbox to be checked (this is available in the Cluster Manager UI by looking at the Properties for the resource).



      I can't figure out how to set this using the MI API. I have searched MSDN and multiple other resources for this without luck. Does anybody know if this is possible? Scripting with Powershell would be fine as well.







      windows wmi windows-clustering






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 7:55









      PaulPaul

      175210




      175210






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.



          It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).



          The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.



          Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.



          I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.



          This is what the whole thing looks like (I ommitted the code for adding the resource):



          using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))

          // This query finds the newly created resource and fills in the
          // private props we'll change. We have to do a manual WQL query
          // because CimSession.GetInstance doesn't populate prop values.
          var query =
          "SELECT PrivateProperties FROM MSCluster_Resource WHERE Id="YOUR-RES-GUID"";

          // Lookup the resource. For some reason QueryInstances does not like
          // the namespace in the regular form - it must be exactly like this
          // for the call to work!
          var res = session.QueryInstances(@"root/mscluster", "WQL", query).First();

          // Add net name dependency so setting UseNetworkName works.
          session.InvokeMethod(
          res,
          "AddDependency",
          new CimMethodParametersCollection

          CimMethodParameter.Create(
          "Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
          );

          // Get private prop bag and set our props.
          var privProps =
          (CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
          privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
          privProps.CimInstanceProperties["UseNetworkName"].Value = 1;

          // Persist the changes.
          session.ModifyInstance(@"rootmscluster", res);



          Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.



          Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314706%2fhow-to-set-cluster-resource-use-network-name-for-computer-name-checkbox-progra%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.



            It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).



            The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.



            Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.



            I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.



            This is what the whole thing looks like (I ommitted the code for adding the resource):



            using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))

            // This query finds the newly created resource and fills in the
            // private props we'll change. We have to do a manual WQL query
            // because CimSession.GetInstance doesn't populate prop values.
            var query =
            "SELECT PrivateProperties FROM MSCluster_Resource WHERE Id="YOUR-RES-GUID"";

            // Lookup the resource. For some reason QueryInstances does not like
            // the namespace in the regular form - it must be exactly like this
            // for the call to work!
            var res = session.QueryInstances(@"root/mscluster", "WQL", query).First();

            // Add net name dependency so setting UseNetworkName works.
            session.InvokeMethod(
            res,
            "AddDependency",
            new CimMethodParametersCollection

            CimMethodParameter.Create(
            "Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
            );

            // Get private prop bag and set our props.
            var privProps =
            (CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
            privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
            privProps.CimInstanceProperties["UseNetworkName"].Value = 1;

            // Persist the changes.
            session.ModifyInstance(@"rootmscluster", res);



            Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.



            Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.






            share|improve this answer



























              0














              I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.



              It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).



              The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.



              Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.



              I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.



              This is what the whole thing looks like (I ommitted the code for adding the resource):



              using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))

              // This query finds the newly created resource and fills in the
              // private props we'll change. We have to do a manual WQL query
              // because CimSession.GetInstance doesn't populate prop values.
              var query =
              "SELECT PrivateProperties FROM MSCluster_Resource WHERE Id="YOUR-RES-GUID"";

              // Lookup the resource. For some reason QueryInstances does not like
              // the namespace in the regular form - it must be exactly like this
              // for the call to work!
              var res = session.QueryInstances(@"root/mscluster", "WQL", query).First();

              // Add net name dependency so setting UseNetworkName works.
              session.InvokeMethod(
              res,
              "AddDependency",
              new CimMethodParametersCollection

              CimMethodParameter.Create(
              "Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
              );

              // Get private prop bag and set our props.
              var privProps =
              (CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
              privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
              privProps.CimInstanceProperties["UseNetworkName"].Value = 1;

              // Persist the changes.
              session.ModifyInstance(@"rootmscluster", res);



              Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.



              Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.






              share|improve this answer

























                0












                0








                0







                I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.



                It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).



                The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.



                Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.



                I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.



                This is what the whole thing looks like (I ommitted the code for adding the resource):



                using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))

                // This query finds the newly created resource and fills in the
                // private props we'll change. We have to do a manual WQL query
                // because CimSession.GetInstance doesn't populate prop values.
                var query =
                "SELECT PrivateProperties FROM MSCluster_Resource WHERE Id="YOUR-RES-GUID"";

                // Lookup the resource. For some reason QueryInstances does not like
                // the namespace in the regular form - it must be exactly like this
                // for the call to work!
                var res = session.QueryInstances(@"root/mscluster", "WQL", query).First();

                // Add net name dependency so setting UseNetworkName works.
                session.InvokeMethod(
                res,
                "AddDependency",
                new CimMethodParametersCollection

                CimMethodParameter.Create(
                "Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
                );

                // Get private prop bag and set our props.
                var privProps =
                (CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
                privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
                privProps.CimInstanceProperties["UseNetworkName"].Value = 1;

                // Persist the changes.
                session.ModifyInstance(@"rootmscluster", res);



                Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.



                Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.






                share|improve this answer













                I was able to figure this out, after a lot of trial and error, and the discovery of an API bug along the way.



                It turns out cluster resource objects have a property called PrivateProperties, which is basically a property bag. Inside, there's a property called UseNetworkName, which corresponds to the checkbox in the UI (and also, the ServiceName property, which is also required for things to work).



                The 'wbemtest' tool was invaluable in finding this out. Once you open the resource instance in it, you have to double-click the PrivateProperties property to bring up a dialog which has a "View Embedded" button, which is then what shows you the properties inside. Somehow I had missed this before.



                Now, setting this property was yet another pain. Due to what looks like a bug in the API, retrieving the resource instance with CimSession.GetInstance() does not populate property values. This misled me into thinking I had to add the PrivateProperties property and its inner properties myself, which only resulted in lots of cryptic errors.



                I finally stumbled upon this old MSDN post about it, where I realized the property is dynamic and automatically set by WMI. So, in the end, all you have to do is know how to get the property bag using CimSession.QueryInstances(), so you can then set the inner properties like any other property.



                This is what the whole thing looks like (I ommitted the code for adding the resource):



                using (var session = CimSession.Create("YOUR_CLUSTER", new DComSessionOptions()))

                // This query finds the newly created resource and fills in the
                // private props we'll change. We have to do a manual WQL query
                // because CimSession.GetInstance doesn't populate prop values.
                var query =
                "SELECT PrivateProperties FROM MSCluster_Resource WHERE Id="YOUR-RES-GUID"";

                // Lookup the resource. For some reason QueryInstances does not like
                // the namespace in the regular form - it must be exactly like this
                // for the call to work!
                var res = session.QueryInstances(@"root/mscluster", "WQL", query).First();

                // Add net name dependency so setting UseNetworkName works.
                session.InvokeMethod(
                res,
                "AddDependency",
                new CimMethodParametersCollection

                CimMethodParameter.Create(
                "Resource", "YOUR_NET_NAME_HERE", CimFlags.Parameter)
                );

                // Get private prop bag and set our props.
                var privProps =
                (CimInstance)res.CimInstanceProperties["PrivateProperties"].Value;
                privProps.CimInstanceProperties["ServiceName"].Value = "YOUR_SVC_HERE";
                privProps.CimInstanceProperties["UseNetworkName"].Value = 1;

                // Persist the changes.
                session.ModifyInstance(@"rootmscluster", res);



                Note how the quirks in the API make things more complicated than they should be: QueryInstances expects the namespace in a special way, and also, if you don't add the network name dependency first, setting private properties fails silently.



                Finally, I also figured out how to set this through PowerShell. You have to use the Set-ClusterParameter command, see this other answer for the full info.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 20:52









                PaulPaul

                175210




                175210





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314706%2fhow-to-set-cluster-resource-use-network-name-for-computer-name-checkbox-progra%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo