Am working on this if the statement that when a value exists it returns a particular message. However, it is always returning the first if statement and not checking the other ones.
if (exists(“5”) of unique values of string value of selects “HealthState from DCIM_Battery” of wmi “root\dcim\sysman”) then (“OK”) else if (exists(“10”) of unique values of string value of selects “HealthState from DCIM_Battery” of wmi “root\dcim\sysman”) then “Degraded/Warning” else if (exists(“20”) of unique values of string value of selects “HealthState from DCIM_Battery” of wmi “root\dcim\sysman”) then (“Major Failure”)else if (exists(“25”) of unique values of string value of selects “HealthState from DCIM_Battery” of wmi “root\dcim\sysman”) then (“Critical Failure”)else if (exists(“30”) of unique values of string value of selects “HealthState from DCIM_Battery” of wmi “root\dcim\sysman”) then (“Non-recoverable error”) else “N/A”
One approach is to create a string that contains the possible values and the text that those values represent then parse the text. Something like
Q: preceding text of first ":" of following text of first ((concatenation "" of unique values of string value of selects "HealthState from DCIM_Battery" of wmi "root\dcim\sysman") & ";") of ("5;OK:10;Degraded/Warning:20;Major Failure:30;Non-recoverable error")
A: OK
T: 89.793 ms
I: singular substring
If the DCIM_Battery class does not exists on a desktop (I don’t have access to any with the required WMI namespace to check), the expression may fail and you could trap that using the “|” operator and default to a “No Battery” string value.
Q: preceding text of first ":" of following text of first ((concatenation "" of unique values of string value of selects "HealthState from DCIM_Battery" of wmi "root\dcim\sysman") & ";") of ("5;OK:10;Degraded/Warning:20;Major Failure:30;Non-recoverable error") | "No Battery"
A: No Battery