WMI OperatingSystemSKU conversion question

Started by stanl, March 26, 2023, 04:28:50 AM

Previous topic - Next topic

stanl

Really like WB maps and getting comfortable using them for enum lookups.  The snippet below has a map created to translate the OperatingSystemSKU from a WMI query into text based on the enum. The keys are all integer, but the WMI query returns an odd numeric, and on subsequent runs of the script often a different return. I bing'd [don't Google anymore] looking for a VBA solution I could translate but most of what I found had someone referring to PS which somehow automagically does the conversion. If it can be done in WB would like to keep it in WB.
Code (WINBATCH) Select


;create WB map to lookup OperatingSystemSKU values
skus = $"0,UNDEFINED
1,ULTIMATE
2,HOME_BASIC
3,HOME_PREMIUM
4,ENTERPRISE
5,HOME_BASIC_N
6,BUSINESS
7,STANDARD_SERVER
8,DATACENTER_SERVER
9,SMALLBUSINESS_SERVER
10,ENTERPRISE_SERVER
11,STARTER
12,DATACENTER_SERVER_CORE
13,STANDARD_SERVER_CORE
14,ENTERPRISE_SERVER_CORE
15,ENTERPRISE_SERVER_IA64
16,BUSINESS_N
17,WEB_SERVER
18,CLUSTER_SERVER
19,HOME_SERVER
20,STORAGE_EXPRESS_SERVER
21,STORAGE_STANDARD_SERVER
22,STORAGE_WORKGROUP_SERVER
23,STORAGE_ENTERPRISE_SERVER
24,SERVER_FOR_SMALLBUSINESS
25,SMALLBUSINESS_SERVER_PREMIUM
26,HOME_PREMIUM_N
27,ENTERPRISE_N
28,ULTIMATE_N
29,WEB_SERVER_CORE
30,MEDIUMBUSINESS_SERVER_MANAGEMENT
31,MEDIUMBUSINESS_SERVER_SECURITY
32,MEDIUMBUSINESS_SERVER_MESSAGING
33,SERVER_FOUNDATION
34,HOME_PREMIUM_SERVER
35,SERVER_FOR_SMALLBUSINESS_V
36,STANDARD_SERVER_V
37,DATACENTER_SERVER_V
38,ENTERPRISE_SERVER_V
39,DATACENTER_SERVER_CORE_V
40,STANDARD_SERVER_CORE_V
41,ENTERPRISE_SERVER_CORE_V
42,HYPERV
43,STORAGE_EXPRESS_SERVER_CORE
44,STORAGE_STANDARD_SERVER_CORE
45,STORAGE_WORKGROUP_SERVER_CORE
46,STORAGE_ENTERPRISE_SERVER_CORE
47,STARTER_N
48,PROFESSIONAL
49,PROFESSIONAL_N
50,SB_SOLUTION_SERVER
51,SERVER_FOR_SB_SOLUTIONS
52,STANDARD_SERVER_SOLUTIONS
53,STANDARD_SERVER_SOLUTIONS_CORE
54,SB_SOLUTION_SERVER_EM
55,SERVER_FOR_SB_SOLUTIONS_EM
56,SOLUTION_EMBEDDEDSERVER
57,SOLUTION_EMBEDDEDSERVER_CORE
58,PROFESSIONAL_EMBEDDED
59,ESSENTIALBUSINESS_SERVER_MGMT
60,ESSENTIALBUSINESS_SERVER_ADDL
61,ESSENTIALBUSINESS_SERVER_MGMTSVC
62,ESSENTIALBUSINESS_SERVER_ADDLSVC
63,SMALLBUSINESS_SERVER_PREMIUM_CORE
64,CLUSTER_SERVER_V
65,EMBEDDED
66,STARTER_E
67,HOME_BASIC_E
68,HOME_PREMIUM_E
69,PROFESSIONAL_E
70,ENTERPRISE_E
71,ULTIMATE_E
72,ENTERPRISE_EVALUATION
76,MULTIPOINT_STANDARD_SERVER
77,MULTIPOINT_PREMIUM_SERVER
79,STANDARD_EVALUATION_SERVER
80,DATACENTER_EVALUATION_SERVER
84,ENTERPRISE_N_EVALUATION
85,EMBEDDED_AUTOMOTIVE
86,EMBEDDED_INDUSTRY_A
87,THINPC
88,EMBEDDED_A
89,EMBEDDED_INDUSTRY
90,EMBEDDED_E
91,EMBEDDED_INDUSTRY_E
92,EMBEDDED_INDUSTRY_A_E
95,STORAGE_WORKGROUP_EVALUATION_SERVE
96,STORAGE_STANDARD_EVALUATION_SERVER
97,CORE_ARM
98,CORE_N
99,CORE_COUNTRYSPECIFIC
100,CORE_SINGLELANGUAGE
101,CORE
103,PROFESSIONAL_WMC
105,EMBEDDED_INDUSTRY_EVAL
106,EMBEDDED_INDUSTRY_E_EVAL
107,EMBEDDED_EVAL
108,EMBEDDED_E_EVAL
109,NANO_SERVER
110,CLOUD_STORAGE_SERVER
111,CORE_CONNECTED
112,PROFESSIONAL_STUDENT
113,CORE_CONNECTED_N
114,PROFESSIONAL_STUDENT_N
115,CORE_CONNECTED_SINGLELANGUAGE
116,CORE_CONNECTED_COUNTRYSPECIFIC
117,CONNECTED_CAR
118,INDUSTRY_HANDHELD
119,PPI_PRO
120,ARM64_SERVER
121,EDUCATION
122,EDUCATION_N
123,IOTUAP
124,CLOUD_HOST_INFRASTRUCTURE_SERVER
125,ENTERPRISE_S
126,ENTERPRISE_S_N
127,PROFESSIONAL_S
128,PROFESSIONAL_S_N
129,ENTERPRISE_S_EVALUATION
130,ENTERPRISE_S_N_EVALUATION
135,HOLOGRAPHIC
138,PRO_SINGLE_LANGUAGE
139,PRO_CHINA
140,ENTERPRISE_SUBSCRIPTION
141,ENTERPRISE_SUBSCRIPTION_N
143,DATACENTER_NANO_SERVER
144,STANDARD_NANO_SERVER
145,DATACENTER_A_SERVER_CORE
146,STANDARD_A_SERVER_CORE
147,DATACENTER_WS_SERVER_CORE
148,STANDARD_WS_SERVER_CORE
149,UTILITY_VM
159,DATACENTER_EVALUATION_SERVER_CORE
160,STANDARD_EVALUATION_SERVER_CORE
161,PRO_WORKSTATION
162,PRO_WORKSTATION_N
164,PRO_FOR_EDUCATION
165,PRO_FOR_EDUCATION_N
168,AZURE_SERVER_CORE
169,AZURE_NANO_SERVER
171,ENTERPRISEG
172,ENTERPRISEGN
175,SERVERRDSH
178,CLOUD
179,CLOUDN
180,HUBOS
182,ONECOREUPDATEOS
183,CLOUDE
184,ANDROMEDA
185,IOTOS
186,CLOUDEN$"


lookup = MapCreate(skus,"",@lf)


;quick test that map works - should return BUSINESS
Message("Testing Value for 6",MapKeyFind(lookup,6,"<Unknown>"))


;use WMI to query OperatingSystemSKU
strComputer = "."
oWMI = GetObject( "winmgmts:\\" : strComputer : "\root\cimv2")
sku = oWMI.ExecQuery( "Select OperatingSystemSKU from Win32_OperatingSystem" )
Message("SKU",sku) ; how to convert to integer value???
Exit


JTaylor

Maybe something like the following.   Was trying to iterate through everything but not acting like I expected.  Maybe this will help though.

sku = oWMI.ExecQuery( "Select * from Win32_OperatingSystem" )

ForEach item in sku
  Message(sku.count,item.OperatingSystemSKU)
Next

Jim

stanl

Thanks Jim.Was assuming per computer selection of operating system would return a single entity, but your code made the difference.


Code (WINBATCH) Select


;create WB map to lookup OperatingSystemSKU values
skus = $"0,UNDEFINED
1,ULTIMATE
2,HOME_BASIC
3,HOME_PREMIUM
4,ENTERPRISE
5,HOME_BASIC_N
6,BUSINESS
7,STANDARD_SERVER
8,DATACENTER_SERVER
9,SMALLBUSINESS_SERVER
10,ENTERPRISE_SERVER
11,STARTER
12,DATACENTER_SERVER_CORE
13,STANDARD_SERVER_CORE
14,ENTERPRISE_SERVER_CORE
15,ENTERPRISE_SERVER_IA64
16,BUSINESS_N
17,WEB_SERVER
18,CLUSTER_SERVER
19,HOME_SERVER
20,STORAGE_EXPRESS_SERVER
21,STORAGE_STANDARD_SERVER
22,STORAGE_WORKGROUP_SERVER
23,STORAGE_ENTERPRISE_SERVER
24,SERVER_FOR_SMALLBUSINESS
25,SMALLBUSINESS_SERVER_PREMIUM
26,HOME_PREMIUM_N
27,ENTERPRISE_N
28,ULTIMATE_N
29,WEB_SERVER_CORE
30,MEDIUMBUSINESS_SERVER_MANAGEMENT
31,MEDIUMBUSINESS_SERVER_SECURITY
32,MEDIUMBUSINESS_SERVER_MESSAGING
33,SERVER_FOUNDATION
34,HOME_PREMIUM_SERVER
35,SERVER_FOR_SMALLBUSINESS_V
36,STANDARD_SERVER_V
37,DATACENTER_SERVER_V
38,ENTERPRISE_SERVER_V
39,DATACENTER_SERVER_CORE_V
40,STANDARD_SERVER_CORE_V
41,ENTERPRISE_SERVER_CORE_V
42,HYPERV
43,STORAGE_EXPRESS_SERVER_CORE
44,STORAGE_STANDARD_SERVER_CORE
45,STORAGE_WORKGROUP_SERVER_CORE
46,STORAGE_ENTERPRISE_SERVER_CORE
47,STARTER_N
48,PROFESSIONAL
49,PROFESSIONAL_N
50,SB_SOLUTION_SERVER
51,SERVER_FOR_SB_SOLUTIONS
52,STANDARD_SERVER_SOLUTIONS
53,STANDARD_SERVER_SOLUTIONS_CORE
54,SB_SOLUTION_SERVER_EM
55,SERVER_FOR_SB_SOLUTIONS_EM
56,SOLUTION_EMBEDDEDSERVER
57,SOLUTION_EMBEDDEDSERVER_CORE
58,PROFESSIONAL_EMBEDDED
59,ESSENTIALBUSINESS_SERVER_MGMT
60,ESSENTIALBUSINESS_SERVER_ADDL
61,ESSENTIALBUSINESS_SERVER_MGMTSVC
62,ESSENTIALBUSINESS_SERVER_ADDLSVC
63,SMALLBUSINESS_SERVER_PREMIUM_CORE
64,CLUSTER_SERVER_V
65,EMBEDDED
66,STARTER_E
67,HOME_BASIC_E
68,HOME_PREMIUM_E
69,PROFESSIONAL_E
70,ENTERPRISE_E
71,ULTIMATE_E
72,ENTERPRISE_EVALUATION
76,MULTIPOINT_STANDARD_SERVER
77,MULTIPOINT_PREMIUM_SERVER
79,STANDARD_EVALUATION_SERVER
80,DATACENTER_EVALUATION_SERVER
84,ENTERPRISE_N_EVALUATION
85,EMBEDDED_AUTOMOTIVE
86,EMBEDDED_INDUSTRY_A
87,THINPC
88,EMBEDDED_A
89,EMBEDDED_INDUSTRY
90,EMBEDDED_E
91,EMBEDDED_INDUSTRY_E
92,EMBEDDED_INDUSTRY_A_E
95,STORAGE_WORKGROUP_EVALUATION_SERVE
96,STORAGE_STANDARD_EVALUATION_SERVER
97,CORE_ARM
98,CORE_N
99,CORE_COUNTRYSPECIFIC
100,CORE_SINGLELANGUAGE
101,CORE
103,PROFESSIONAL_WMC
105,EMBEDDED_INDUSTRY_EVAL
106,EMBEDDED_INDUSTRY_E_EVAL
107,EMBEDDED_EVAL
108,EMBEDDED_E_EVAL
109,NANO_SERVER
110,CLOUD_STORAGE_SERVER
111,CORE_CONNECTED
112,PROFESSIONAL_STUDENT
113,CORE_CONNECTED_N
114,PROFESSIONAL_STUDENT_N
115,CORE_CONNECTED_SINGLELANGUAGE
116,CORE_CONNECTED_COUNTRYSPECIFIC
117,CONNECTED_CAR
118,INDUSTRY_HANDHELD
119,PPI_PRO
120,ARM64_SERVER
121,EDUCATION
122,EDUCATION_N
123,IOTUAP
124,CLOUD_HOST_INFRASTRUCTURE_SERVER
125,ENTERPRISE_S
126,ENTERPRISE_S_N
127,PROFESSIONAL_S
128,PROFESSIONAL_S_N
129,ENTERPRISE_S_EVALUATION
130,ENTERPRISE_S_N_EVALUATION
135,HOLOGRAPHIC
138,PRO_SINGLE_LANGUAGE
139,PRO_CHINA
140,ENTERPRISE_SUBSCRIPTION
141,ENTERPRISE_SUBSCRIPTION_N
143,DATACENTER_NANO_SERVER
144,STANDARD_NANO_SERVER
145,DATACENTER_A_SERVER_CORE
146,STANDARD_A_SERVER_CORE
147,DATACENTER_WS_SERVER_CORE
148,STANDARD_WS_SERVER_CORE
149,UTILITY_VM
159,DATACENTER_EVALUATION_SERVER_CORE
160,STANDARD_EVALUATION_SERVER_CORE
161,PRO_WORKSTATION
162,PRO_WORKSTATION_N
164,PRO_FOR_EDUCATION
165,PRO_FOR_EDUCATION_N
168,AZURE_SERVER_CORE
169,AZURE_NANO_SERVER
171,ENTERPRISEG
172,ENTERPRISEGN
175,SERVERRDSH
178,CLOUD
179,CLOUDN
180,HUBOS
182,ONECOREUPDATEOS
183,CLOUDE
184,ANDROMEDA
185,IOTOS
186,CLOUDEN$"


lookup = MapCreate(skus,"",@lf)
;use WMI to query OperatingSystemSKU
strComputer = "."
oWMI = GetObject( "winmgmts:\\" : strComputer : "\root\cimv2")
sku = oWMI.ExecQuery( "Select * from Win32_OperatingSystem" )
ForEach item in sku
  value =item.OperatingSystemSKU
  Message("SKU",MapKeyFind(lookup,value,"<Unknown>"))
Next


Exit

JTaylor

Glad it helped.

While it went beyond what you needed, I was trying to iterate through all the properties but wasn't able to figure that out before I had to quit.

Jim

JTaylor

I am sure there is a cleaner way to do this but for what it is worth....

Code (winbatch) Select


;use WMI to query OperatingSystemSKU
strComputer = "."
oWMI = GetObject( "winmgmts:\\" : strComputer : "\root\cimv2")
pro = oWMI.Get("Win32_OperatingSystem")
sku = oWMI.ExecQuery( "Select * from Win32_OperatingSystem" )
ForEach sitem in sku
   txt = ""
Next
IntControl(73,2,0,0,0)

ForEach item in pro.Properties_
  txt = txt:item.Name:"  -  "
  pname = item.Name
  val = sitem.%pname%:""
  txt = txt:val:@CRLF
Next
    clipput(txt)
    Message("List",txt)

Exit
:WBERRORHANDLER
val = "NonText"
IntControl(73,2,0,0,0) ; Re-arm error handler
Return


stanl

Nice use of IntControl 73.  There are a lot of useful scripts out there to detail specific properties, and not sure if all are needed. I got interested in SKU enum for Win10<>Win11 [I don't have Win11 and even though my Surface Pro is not 'eligible' to use it... what am I supposed to do, throw it away???]. 


But I have learned that just selecting by specific property via WMI takes some thought ;) ;)

JTaylor

Yeah...probably should have went with recursion but since this was simply trying to figure out how to pull more than just the one property, I was able to make myself quit with what I accomplished :)

This did seem a bit more complicated than I thought it should but I am probably missing something obvious.


Jim

stanl

NP. I have always been interested in Enums. With the WindowsOperatingSystem seems the enum for OperatingSystemSKU could differ [something I proved] from the map I created in my initial post. So, when first run on the lookup came back as "CORE" but when I ran this simple PS script


Function get-enumValues
{
   Param([string]$enum)
   $enumValues = @{}
   [enum]::getvalues([type]$enum) |
   ForEach-Object {
      $enumValues.add($_, $_.value__)
   }
   $enumValues
}
get-enumValues -enum "microsoft.powershell.commands.OperatingSystemSKU"



It came back as  "WindowsHome"


So, I guess the next Holy Grail is to obtain an enum programmatically as a lookup for a particular translation.

JTaylor

Assuming I understand, that is in MUILanguages.   It is a stringArray but I can't figure out how to read it in WinBatch.  Can probably do a conversion using C#.

You might find this helpful, if you don't already have it.

https://www.microsoft.com/en-us/download/details.aspx?id=8572


Jim

stanl

Just wanted to enumerate: the fact that a starter.. Again NP

td

The MSFT docs list the OS SKUs here:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.operatingsystemsku?view=powershellsdk-1.1.0

For fun, I did a copy&paste to a WIL ml string and added a few lines to parse the file into a WIL map. If you have a recent copy of the Win32 SDK, you could do the same from one of the SDK header files as well. MSFT states that the SKU values do not change. They will only add new ones if needs be.

I tried to test the results against the posted ps script but it gave me a type-casting error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on March 27, 2023, 05:38:34 PM
I tried to test the results against the posted ps script but it gave me a type-casting error.


Funny, it worked for me but on subsequent tries [PS 5.1 in both 32/64 ISE] it failed with type conversion error. So, indeed PS can be flakey.


I added a few more enums... some worked, some didn't. Then I read that the errors would be overcome if you added a reference to Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll --- I found it in my Visual Studio 2019 Community folder and played around


Function get-enumValues
{
   Param([string]$enum)
   $enumValues = @{}
   [enum]::getvalues([type]$enum) |
   ForEach-Object {
      $enumValues.add($_, $_.value__)
   }
   $enumValues
}


Add-Type "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\TestTools\TeamExplorerClient\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll"
get-enumValues -enum "microsoft.powershell.commands.OperatingSystemSKU"
#get-enumValues -enum "microsoft.powershell.commands.WebRequestMethod"
#get-enumValues -enum "microsoft.powershell.commands.OSType"
#get-enumValues -enum "System.Diagnostics.Eventing.Reader.StandardEventLevel"



and yes, the enums all worked but with a lot of initial errors... commented the Add-Type line and all still worked without error. Not great but the data can be output to text and easily converted to WB maps.


Guess this really hijacks the thread; have to take it up with the user who started it ::) ::) [size=78%] [/size]