• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1081
  • Last Modified:

How do I convert from a Value code to a Valuemap string in a WMI MOF in Powershell?

After some marathon googling I'm still stuck on a simple task.  I can write a WMI query to retrieve a WMI class (in this case from HP's provided WBEM classes for ProLiant servers).  In this case, I am trying to get the NIC Team type.  The object returned contains the code.  Looking into the associated MOF file, I can see that the values correspond to a ValueMap, but I can't figure out how to convert the integer I have with the string in the MOF.  I have a feeling it's right under my nose, so could someone please show me?
$server = "SERVER1"
$wmiQuery = "SELECT * from HP_EthernetTeam"	
$nicTeam = Get-WmiObject -Namespace "root\HPQ" -ComputerName $server -query "$wmiQuery"
Write-Host Current mode $nicTeam.TeamCurrentOperatingMode
Current mode 1011

Open in new window

  • 2
  • 2
1 Solution
The easiest thing to do is to use a switch statement

switch -exact ($value)
   "1101"    {"String Value"}
   "1001"    {"Another Value"}
   default    {"Unknow value: $_"}

trader37Author Commented:
Well that's obviously going to allow me to reach the end goal for this script, it doesn't help on subsequent ones.  Basically, I don't want to have to go into the .mof file for every WMI/WBEM script I'm going to write to look at the values, and then hard code them into my script.

I want to be able to take values and reference them against their associated valuemap inside the .mof file to figure out what the strings should be.  This may be more a "how do I use a WBEM feature?" question than "how do I use a powershell feature?".
There is no Powershell, or any other for that matter, feature that does what you want.

I suppose you could write a mof parsing script and generate the info, but I do not imagine that is very simple.
trader37Author Commented:
Which begs the question why have valuemaps anyway? >.<

I did see one document mention that you *could* do it, but it didn't explain how.  However, it may be that the solution they were thinking of was parsing the file.

Since it's the closest I'll get, the points are yours.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now