1 2 Previous Next 22 Replies Latest reply on Oct 8, 2014 10:00 AM by Jim Wilson

    nexec to run a wmic command

    Jim Wilson

      Just wondering if anyone has encountered and resolved the following problem.

       

      Executing this command directly works just fine:

       

      wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")


      but

       

      nexec vw-hou-cus-sp77 wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")

      RESULTS:

      Node - VW-HOU-CUS-SP77

      ERROR:

      Description = Invalid query

       

      The problem is that the special chars (\ and “) are getting stripped.

      I have tried numerous variations of attempts to escape them to get the correct syntax passed to WMI but haven’t found the magic spell yet.

       

      I’m hoping that someone out there will have come across this situation and resolved it

       

      Thanks & Regards,

      Jim

        • 1. Re: nexec to run a wmic command
          R V

          Have you tried setting single quotes for the outermost positions, e.g.

          ... groupcomponent='win32_group........COMPUTERNAME%\"'

           

          Another option may be experimenting with doubled double-quotes, or doubled backslashes or any combination of them.


          • 2. Re: Re: nexec to run a wmic command
            Jim Wilson

            Thanks Reinhard, but that has not resolved the issue.

             

            C:\Users\Administrator>nexec vw-hou-cus-sp77 wmic path win32_groupuser where (groupcomponent='"win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\""')

             

            Node - VW-HOU-CUS-SP77

            ERROR:

            Description = Invalid query

             

            nexec is still stripping the special chars:

             

            C:\Users\Administrator>nexec vw-hou-cus-sp77 echo wmic path win32_groupuser where (groupcomponent='"win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\

            ""')

            wmic path win32_groupuser where (groupcomponent=win32_group.name=Administrators,

            domain=VW-HOU-CUS-SP77)

             

            I have tried doubling the \ and " chars in various ways, but have not found a setting that works.

            • 3. Re: Re: Re: nexec to run a wmic command
              Cody Dean

              This worked for me:

              nexec -ncq SERVERNAME cmd /c 'wmic path win32_groupuser where groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

              • 4. Re: Re: Re: nexec to run a wmic command
                Jim Wilson

                Are you sure?  There are unpaired parenthesis in there...

                • 5. Re: Re: Re: nexec to run a wmic command
                  Cody Dean

                  Opps!  Something ate it.  Here ya go.  Also, why not just use net localgroup administrators?  WMIC can be problematic at times.

                   

                  nexec -ncq SERVERNAME cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                  • 6. Re: nexec to run a wmic command
                    Mike Jones

                    wmic can be problematic, if you echo something to it works all the time.

                     

                    So something like

                    nexec servername cmd /c "echo. | wmic computersystem get manufacturer"

                    • 7. Re: nexec to run a wmic command
                      Cody Dean

                      As odd as it sounds, we actually have discovered a handful of servers that had corrupted WMI catalogs, and a WMI call would hang forever causing the job to hang as well.  Granted, we had the Sysadmins fix their systems, but it was still enough of a concern that we try to limit the times we use WMI.

                      • 8. Re: nexec to run a wmic command
                        Mike Jones

                        if you still have a server in that state it might be worth trying with the echo, the reason we use this is that we had a number of server where the wmic call would hang forever and this seemed to fix it

                        • 9. Re: Re: nexec to run a wmic command
                          Jim Wilson

                          Thanks Cody & Mike - some progress.

                           

                          Running Mike's echo suggestion works:

                           

                          C:\Users\jiwilson>nexec vw-hou-cus-sp78 cmd /c "echo. | wmic computersystem get manufacturer"

                          Manufacturer

                          VMware, Inc.

                           

                          but when I put the original query in, not so good:

                           

                          C:\Users\jiwilson>nexec vw-hou-cus-sp78 cmd /c "echo. | wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")"

                           

                          Node - VW-HOU-CUS-SP78

                          ERROR:

                          Description = Invalid query

                           

                          Using Cody's suggested format:

                           

                          C:\Users\Administrator>nexec -ncq vw-hou-cus-sp78 cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                           

                          No Instance(s) Available.

                           

                          If I hard code the value for COMPUTERNAME:

                           

                          C:\Users\Administrator>nexec -ncq vw-hou-cus-sp78 cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"vw-hou-cus-sp78\"")'

                          GroupComponent                                              PartComponent

                           

                          win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="Administrator"

                          win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="rdsroot"

                          win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="rdsmon"

                           

                          If I hard code the COMPUTERNAME into the echo version, it still does not work

                           

                          C:\Users\Administrator>nexec vw-hou-cus-sp78 cmd /c "echo. | wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"vw-hou-cus-sp78\"")"

                           

                          Node - VW-HOU-CUS-SP78

                          ERROR:

                          Description = Invalid query

                           

                          So, the closest so far still needs a way to substitute the COMPUTERNAME

                           

                          Thanks & Regards,

                          Jim

                          • 10. Re: nexec to run a wmic command
                            Cody Dean

                            Try your command with the -ncq, which allows you to use double quotes inside the command

                             

                            nexec -ncq SERVERNAME cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                             

                            This was the output I got:

                             

                            GroupComponent                                              PartComponent

                             

                             

                            win32_group.domain="SERVERNAME",name="Administrators"  \\SERVERNAME\ro

                            ot\cimv2:Win32_UserAccount.Domain="SERVERNAME",Name="USER1"

                            win32_group.domain="SERVERNAME",name="Administrators"  \\SERVERNAME\ro

                            ot\cimv2:Win32_UserAccount.Domain="SERVERNAME",Name="USER2"

                            • 11. Re: nexec to run a wmic command
                              Cody Dean

                              I was able to do similar with Mike's sugestion:

                               

                              nexec -ncq SERVERNAME cmd /c 'echo. | wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                               

                              GroupComponent                                              PartComponent

                               

                               

                              win32_group.domain="SERVERNAME ",name="Administrators"  \\SERVERNAME \ro

                              ot\cimv2:Win32_UserAccount.Domain="SERVERNAME ",Name="USER1"

                              win32_group.domain="SERVERNAME ",name="Administrators"  \\SERVERNAME \ro

                              ot\cimv2:Win32_UserAccount.Domain="SERVERNAME ",Name="USER2"

                              • 12. Re: Re: nexec to run a wmic command
                                Jim Wilson

                                Is your SERVERNAME remote?

                                 

                                For your update (post number 10), my command and your command are exactly the same, except mine only works if I hard-code the value for COMPUTERNAME as the remote target.

                                 

                                I suspect that the variable it is getting substituted for the source server name where the nexec is being executed from.

                                 

                                For the Echo format, I have to replace the ' (single quote) with " (double quote), else i get "invalid verb".  With " I get "Invalid query"

                                 

                                C:\Users\Administrator>nexec -ncq vw-hou-cus-sp78 cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                                 

                                No Instance(s) Available.

                                 

                                C:\Users\Administrator>nexec -ncq vw-hou-cus-sp78 cmd /c 'wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"vw-hou-cus-sp78\"")'

                                GroupComponent                                              PartComponent

                                 

                                win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="Administrator"

                                win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="rdsroot"

                                win32_group.domain="vw-hou-cus-sp78",name="Administrators"  \\VW-HOU-CUS-SP78\root\cimv2:Win32_UserAccount.Domain="VW-HOU-CUS-SP78",Name="rdsmon"

                                 

                                C:\Users\Administrator>nexec -ncq vw-hou-cus-sp78 cmd /c 'echo. | wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"%COMPUTERNAME%\"")'

                                Invalid Verb.

                                 

                                C:\Users\Administrator>nexec vw-hou-cus-sp78 cmd /c "echo. | wmic path win32_groupuser where (groupcomponent="win32_group.name=\"Administrators\",domain=\"vw-hou-cus-sp78\"")"

                                 

                                Node - VW-HOU-CUS-SP78

                                ERROR:

                                Description = Invalid query

                                 

                                Any further ideas welcomed

                                 

                                Thanks & Regards,

                                Jim

                                • 13. Re: nexec to run a wmic command
                                  Mike Jones

                                  As long as the %COMPUTERNAME% is getting transferred to the remote host that should resolve locally to the hostname on which it is running

                                   

                                  This does seem to be a complicated way to return a list of users in a local group.

                                   

                                  I would tend to use

                                  nexec servername net localgroup administrators | grep -v -e Alias -e Comment -e Members -e "--"

                                  • 14. Re: nexec to run a wmic command
                                    Jim Wilson

                                    Thanks Mike!

                                     

                                    I am not sure I agree that using WMI is any more complicated that any other method.

                                    It's only complicated because we can't work out the syntax that nexec won't foul up :-)

                                     

                                    But I'm happy to suggest an alternative that achieves the same result, so let me see how that goes. 

                                    1 2 Previous Next