I have a bit of a project where I am scanning all assets for my organization for instances of the log4j vulnerability and am trying to organize all of the data into a csv before beginning to remediate all of the vulnerabilities. I have around 150 text files, some containing the desired string ("log4j-core-[version number].jar"), some not, and some with 10 instances of the string. The end goal is to have all the useful data in 1 csv organized into two columns ("asset tag" and "log4j version number" (and maybe a couple others like IP if its easy)). I read some other posts describing how to do this -> add them into arrays and then make a psobject containing all arrays and export that psobject to csv. The problem with that solution is that it will add 1 item from each array in 2 different columns for each number in the array. And the problem with that is I need to find a way to associate the two properly since they're not each 1-to-1; sometimes 1 asset can have 10 instances of log4j and I need them to correlate accurately, so I need column 1 to list 1 item and for column 2 to list a variable number of items depending on how many of them are associated with the file they were pulled from. Any help you can provide would be much appreciated.
Below is my code. It runs successfully and I get all of the desired items in each array. The text files have the asset tag in their name if you're wondering where I got that.
$files = Get-ChildItem -Path '\\[IP ADDRESS REMOVED]\Log4J\logs' -filter '*.txt'
$version = @()
$asset = @()
foreach ($f in $files)
{if ((get-content -Path $f.FullName) -like "*log4j-core*")
{$asset += {$f.Name -split "_scanlog.txt"} ;$version += Get-Content -Path $f.fullname | Out-String -Stream | Select-String "log4j-core"}}