Parsing WMI Queries

Forums Desktop Info Parsing WMI Queries

Tagged: ,

Viewing 8 reply threads
  • Author
    Posts
    • #2712
      phlegmerphlegmer
      Participant

        Greetings,

        It has been years since I looked for updates to this fine product and boy was I surprised on how much activity there has been!

        I’m still trying to understand the new syntax for the .ini files. One thing that has changed is the OS Version display. It now uses a WMI call. Is there a way to parse the %caption% response so I can pull just the bits I want?

        For example namespace:root\cimv2,query:Win32_OperatingSystem,display:%caption% will show
        “Microsoft Windows Server 2019 Standard”
        Let’s say that I don’t care if it shows Microsoft and want to omit it from the display. Is that possible?

        Thanks!

      • #2715
        GlennGlenn
        Keymaster

          Not right now.

          The thought started the brain ticking over though.

          Idea 1: I can imagine a substring tool for example. substr(string,start,length)
          display: {{subtr(%caption%\,11)}}

          Idea 2: A tool that breaks down a string field into words. Your example would produce 5 new fields: %caption_1%, %caption_2% etc. You can then display %caption_3% %caption_4% %caption_5%. You would have to know what the output of the original string field looks like. I’ll have to give implementation some more thought.

        • #2780
          phlegmerphlegmer
          Participant

            This is kind of what I’m looking for but not sure if REGEX can be used in the .ini

            https://stackoverflow.com/questions/27306449/powershell-gwmi-win32-operatingsystem-trim-output

            • #2782
              GlennGlenn
              Keymaster

                Possibly, but I don’t have a good grasp of regex, I’ve tried but it eludes me.

            • #2783
              phlegmerphlegmer
              Participant

                Since the OS Version ini option now uses an WMI call, the added “Microsoft” text really messes with my right column mojo.

                This PS script really returns what I’m hoping to have

                gwmi Win32_OperatingSystem | % Caption | % split ' ' 2 | select -last 1

                Oh well, guess I just need to be patient and see what v2.5 will bring. 🙂

                • #2784
                  GlennGlenn
                  Keymaster

                    There you go, problem solved:

                    CMD=text:Windows,file:powershell.exe,parameters:gwmi Win32_OperatingSystem | % Caption | % split ‘ ‘ 2 | select -last 1

                • #2785
                  phlegmerphlegmer
                  Participant

                    Oh boy! So close. Now if I can tag on

                    gwmi Win32_OperatingSystem | % OSArchitecture

                    or

                    WMI=namespace:root\cimv2,query:Win32_OperatingSystem,display:%OSArchitecture%

                    at the end, I think life will be good again. 🙂

                  • #2800
                    phlegmerphlegmer
                    Participant

                      Allow me to explain.

                      Before we had it show the following:
                      Windows Server 2019 (64-Bit)

                      With the cool new CMD feature you showed me, I can get
                      Windows Server 2019

                      Can the %OSArchitecture% somehow be appended to the end of the command you sent? Or maybe can “gwmi Win32_OperatingSystem | % OSArchitecture” type code be used on the left column along with a little text?

                      If not, not a big deal but thought I’d ask. 🙂

                      • #2802
                        GlennGlenn
                        Keymaster

                          you use user variables. you have two commands, each sets a user variable. a third command displays the user variables.

                          unfortunately Powershell appends a line feed to it’s output. Your task is to figure out how to strip that trailing line feed from the output.

                      • #2810
                        phlegmerphlegmer
                        Participant

                          OK, I think I have some alternate PS script that will output what I would like sans CR/LF

                          I’ve distilled it to 2 lines. The last (3rd) line is just to show the output in PS.

                          I can’t quite figure out how to DesktopInfo’ize it so that it will work in the .ini. 🙁

                          • This reply was modified 2 years ago by phlegmerphlegmer.
                        • #2813
                          GlennGlenn
                          Keymaster

                            you just have to get it to a single line command or put it in a script file and call the script file from DTI

                          • #2814
                            phlegmerphlegmer
                            Participant

                              Couldn’t get it whittled down to 1 line. 🙁 I resorted to having it call the script and all looks as it should. Quite the work around but it is what it is.

                              Thanks!

                          Viewing 8 reply threads
                          • The topic ‘Parsing WMI Queries’ is closed to new replies.
                          Glenn's Page