Parsing WMI Queries
 
Notifications
Clear all

We had a major storm through here recently and we suffered damage to the house roof and ceilings. I just received the quote to repair. I’m hoping that a small fraction of the 80,000 odd people that download SDIO and/or Desktop Info every month won’t mind chipping in a few dollars to help out. Click on the big blue button at the bottom of the page to help us keep a roof over our heads, literally!

Guests have read-only access to our forums. If you wish to participate you will need to register. Be sure to activate your account from the email sent to you when you register.

[Closed] Parsing WMI Queries

12 Posts
2 Users
0 Reactions
1,452 Views
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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:rootcimv2,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!


   
Glenn
(@glenn)
Member Admin
Joined: 7 years ago
Posts: 1811
 

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.


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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


   
Glenn
(@glenn)
Member Admin
Joined: 7 years ago
Posts: 1811
 

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


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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. 🙂


   
Glenn
(@glenn)
Member Admin
Joined: 7 years ago
Posts: 1811
 

There you go, problem solved:

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


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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

gwmi Win32_OperatingSystem | % OSArchitecture

or

WMI=namespace:rootcimv2,query:Win32_OperatingSystem,display:%OSArchitecture%

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


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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. 🙂


   
Glenn
(@glenn)
Member Admin
Joined: 7 years ago
Posts: 1811
 

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

CMD=text:Windows,file:powershell.exe,parameters:gwmi Win32_OperatingSystem | % Caption | % split ‘ ‘ 2 | select -last 1,set:win32_os,hidden:1
WMI=namespace:rootcimv2,query:Win32_OperatingSystem,display:%OSArchitecture%,set:win32_arch,hidden:1
text=display:%win32_os% (%win32_arch%)

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.


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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

$Computer = gwmi Win32_operatingSystem | Select-Object Caption, OSArchitecture
$Computer = "$($Computer.Caption) ($($Computer.OSArchitecture))" | % {$_.replace("Microsoft ","")}
$Computer

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. 🙁


   
Glenn
(@glenn)
Member Admin
Joined: 7 years ago
Posts: 1811
 

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


   
(@phlegmer)
Eminent Member Registered
Joined: 6 years ago
Posts: 27
Topic starter  

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!


   
Glenn's Page