I have created this query to know the license status of Windows OS. Currently I am using the complete sentence that is in the description variable - “Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel”. I am trying to use LIKE and search for “VOLUME_KMSCLIENT” but the wildcard % is not working. Is there some other way to write this query? Why does the wildcard not work?
if (exists wmi and exists wmi “\root\cimv2”) then (if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “0” as string then “UnLicensed” else if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “1” as string then “Licensed” else if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “2” as string then “OOBGrace” else if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “3” as string then “OOTGrace” else if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “4” as string then “NonGenuineGrace” else if (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) contains “5” as string then “Notification” else “ExtendedGrace”)else “Cannot query the License Status”
Apologies, but this is only a partial answer for you.
For the initial testing and development of this relevance, I would put the basic wmi query in an analysis on it’s own, just to see whether you can get the return values you’re expecting. Once it’s working, you may want to use the relevance below to give you a slightly more streamlined result, which only does the WMI query once, rather than up to 5 times (if returning “5”) in your original code.
if (exists wmi and exists wmi “\root\cimv2”) then ( ((if it contains “1” then “Licensed” else if it contains “2” then “OOBGrace” else if it contains “3” then “OOTGrace” else if it contains “4” then “NonGenuineGrace” else if it contains “5” then “Notification” else “ExtendedGrace”) of it) of (string value of select “LicenseStatus from SoftwareLicensingProduct WHERE Description = ‘Windows Operating System - Windows Server®, VOLUME_KMSCLIENT channel’” of wmi “\root\cimv2:SoftwareLicensingProduct”) ) else “Cannot query the License Status”
Generally, the way I try to write relevance (read right to left) is something like:
{reformat data for output} of ( {test 1 of data, test 2 of data, etc.} ) of {format data suitable for testing} of {pull data from source}
Thanks Jim for the insight. I had no idea the query can be shortened like that. I am hard pressed in finding books/articles that will give a better understanding of how to write such queries in bigfix. Please let me know if you know any.
I will wait for someone to answer on the usage of LIKE with wildcards.
Thanks a lot Lee. It worked like a charm. Can you also guide me to some books/articles that will help me better understand how to script relevance queries.