Parsing WMI Queries
› Forums › Desktop Info › Parsing WMI Queries
Tagged: powershell, wmi
- This topic has 11 replies, 2 voices, and was last updated 2 years ago by
phlegmer.
-
AuthorPosts
-
-
25 March, 2020 at 12:51 am #2712
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!
-
25 March, 2020 at 6:52 am #2715
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.
-
1 April, 2020 at 7:31 am #2780
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
-
1 April, 2020 at 10:39 pm #2782
Possibly, but I don’t have a good grasp of regex, I’ve tried but it eludes me.
-
-
2 April, 2020 at 8:16 am #2783
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. 🙂
-
2 April, 2020 at 8:46 am #2784
There you go, problem solved:
CMD=text:Windows,file:powershell.exe,parameters:gwmi Win32_OperatingSystem | % Caption | % split ‘ ‘ 2 | select -last 1
-
-
3 April, 2020 at 12:25 am #2785
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. 🙂
-
4 April, 2020 at 1:24 am #2800
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 2019Can 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. 🙂
-
4 April, 2020 at 9:31 am #2802
you use user variables. you have two commands, each sets a user variable. a third command displays the user variables.
1234CMD=text:Windows,file:powershell.exe,parameters:gwmi Win32_OperatingSystem | % Caption | % split ‘ ‘ 2 | select -last 1,set:win32_os,hidden:1WMI=namespace:root\cimv2,query:Win32_OperatingSystem,display:%OSArchitecture%,set:win32_arch,hidden:1text=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.
-
-
9 April, 2020 at 3:07 am #2810
OK, I think I have some alternate PS script that will output what I would like sans CR/LF
123$Computer = gwmi Win32_operatingSystem | Select-Object Caption, OSArchitecture$Computer = "$($Computer.Caption) ($($Computer.OSArchitecture))" | % {$_.replace("Microsoft ","")}$ComputerI’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
phlegmer.
-
This reply was modified 2 years ago by
-
9 April, 2020 at 7:55 pm #2813
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
-
10 April, 2020 at 1:45 am #2814
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!
-
-
AuthorPosts
- The topic ‘Parsing WMI Queries’ is closed to new replies.