Extracting file contents from the latest modified .xml file

Good day All, I need your expertise to accomplish the following mission related to BigFix Inventory.

A HW scan creates multiple output .xml files in C:\Program Files (x86)\BigFix Enterprise\BES Client\LMT\CIT\tlm_hw_scans directory.

12/01/2020 08:15 PM 1,675 tlm_hw_202012011715_1606871717.xml
12/09/2020 12:54 PM 1,671 tlm_hw_202012020908_1606918131.xml
12/09/2020 12:48 PM 1,631 tlm_hw_202012020908_1606918165.xml
12/09/2020 01:22 PM 1,675 tlm_hw_202012091322_1607538129.xml

I am looking for a relevance script to extract the Serial Number from ONLY the latest copy of the above .xml file which is this one below based on the date and time.

12/09/2020 01:22 PM 1,675 tlm_hw_202012091322_1607538129.xml

This is important as Serial Number value could be different when dealing with virtual machine environment when a virtual image is moved from one hypervisor to another.

I found this analysis called “Serial Number based on BFI HW Scan” from this link https://bigfix.me/analysis/details/2998606.

It has the following relevance script called “Serial Number based on BFI HW Scan” and it does what I want. But the problem is that it reports back all the Serial Number values from each *.xml file when the value is different. It works very well if the Serial Number value is the same from all *.xml files.

I have been playing around the “modification time of it” function with the relevance script below and no luck getting it to work.

I need this relevance script below to ONLY extract the Serial Number value from the latest copy of tlm_hw-*.xml file based on the date and time. This will report back the latest current Serial Number value and that all I care for. I know it can be done and I need some experts to help me out here. Thanks.

if (name of operating system as lowercase starts with “win”) then (if (exists folder ((if (version of client >= “9” as version) then (pathname of parent folder of data folder of client) else (pathname of parent folder of regapp “besclient.exe”)) & “\LMT\CIT\tlm_hw_scans”)) then (unique values of (it as text) of (xpaths “Hardware/ComponentID/SerialNumber” of xml documents of files whose (name of it as lowercase contains “tlm_hw_”) of folders ((if (version of client >= “9” as version) then (pathname of parent folder of data folder of client) else (pathname of parent folder of regapp “besclient.exe”)) & “\LMT\CIT\tlm_hw_scans”))) else “Missing Hardware Scan”) else (if (exists folder (((if (version of client >= “9” as version) then (pathname of parent folder of data folder of client) else (pathname of parent folder of parent folder of client folder of site “actionsite”))) & “/LMT/CIT/tlm_hw_scans”)) then (if exists property “xml document” then (unique values of (it as text) of (xpaths “Hardware/ComponentID/SerialNumber” of xml documents of files whose (name of it as lowercase contains “tlm_hw_”) of folders (((if (version of client >= “9” as version) then (pathname of parent folder of data folder of client) else (pathname of parent folder of parent folder of client folder of site “actionsite”))) & “/LMT/CIT/tlm_hw_scans/”))) else “Missing Hardware Scan” ) else “No information”)

So when I looked at all the files on my endpoint, they all had the same serial, so does it matter which file?

I started playing with the XML but had some trouble.

This will pull it from the most recent file on a windows server.

substring before “<” of substring after “” of lines whose ((it does not contain “><”) and (it contains “SerialNumber”)) of file (pathname of it of items 1 of ( maximum of creation times of files whose ( name of it as lowercase starts with “tlm_hw” ) of it, files whose ( name of it as lowercase starts with “tlm_hw” of it ) of it ) whose ( item 0 of it = creation time of item 1 of it ) of folder (parent folder of data folder of client as string & “\LMT\CIT\tlm_hw_scans”))

1 Like

Thanks Jared, yours seems to work very well. However, if the serial number is different from each *.xml file, I would get this error below after it returned back the serial number from the last modified .xml file. You could try to modify the serial number in one of the .xml file and see if you get the same error.

0114-7385-5562-1992-2924-2115-85
Error: Singular expression refers to non-unique object.

Also there is a syntax error from yours relevance below.

substring before “<” of substring after “”

should be

substring before “<” of substring after “>”

By the way, what is the different between “maximum of creation times” and “maximum of modification times” as they both seem to do the same thing?

Basically if the file was modified after it was created it would show the modified time vs the create time. I will have to play with the the serial numbers when I have some time.

1 Like

Thanks Jared. Appreciate your time to work on this.

1 Like