Link to home
Start Free TrialLog in
Avatar of trader37
trader37

asked on

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
 
Output:
Current mode 1011

Open in new window

Avatar of BSonPosh
BSonPosh
Flag of United States of America image

The easiest thing to do is to use a switch statement

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

}
Avatar of trader37
trader37

ASKER

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?".
ASKER CERTIFIED SOLUTION
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.