There are 2 csv files - MS_Monthly_CVE.csv containing the KB list of vulnerabilities and the autocheck.csv where it should update with info taken from first file.
$data = Import-Csv C:\Users\test\Downloads\MS_Monthly_CVE.csv
$checks = import-csv C:\Users\test\Downloads\autocheck.csv
$kbhash = @{}
foreach($cve in $data){
$kbhash.($cve.Supercedence) = $cve.KBArticle
}
foreach($check in $checks){
$jxpathkbs = $check.jxpath -replace ".*?/hotfix_id,'([^']+)'\)\).*",'$1'
$kbnums = @($jxpathkbs -split "," -replace "KB")
$newkbfound = $false
$newkbs = $kbnums.clone()
foreach($kb in $kbnums){
if($kbhash.ContainsKey($kb)){
if($newkbs -notcontains $kbhash.$kb){
# Write-Host "$kb -> $($kbhash.$kb)" -ForegroundColor Green
$newkbfound = $true
$newkbs += $kb
}
else{
# Write-Host $kb -ForegroundColor Yellow
}
}
}
if($newkbfound){
$newjxpathkbs = $check.jxpath -replace "(?<=/hotfix_id,')[^']+(?='\)\))",(@($newkbs | ForEach-Object {"KB$_"}) -join ",")
$newjxpathkbs
Write-Host "Orig: $($check.jxpath)" -ForegroundColor Yellow
Write-Host "New : $newjxpathkbs" -ForegroundColor Green
Write-Host "--------------------"
}
else{
Write-Host "NoCh: $($check.jxpath)" -ForegroundColor Gray
}
}
for instance if we pick a row from autocheck.csv (/mapModel/fleet/hostsRq/response/hosts[windowsPatchesRq[responseStatus=‘OK’][not(ext:isAnyFromCsv(response/hotfix_id,‘KB5004948,KB5005043,KB5005573,KB5006669,KB5007192,KB5008207,KB5009546,KB5010359,KB5011495,KB5012596,KB5013952,KB5014702’))]]/analysisObjectGoId) - take 5014702. In the MS_Monthly_CVE.csv should search in I column (Supercedence) for this number.
For instance 5014702 can be found in I277
If Supercedence is 5014702
that means KB5014702. Then check in MS_Monthly_CVE.csv in the same row as I but in B column (B277) the number (5015808
), add KB in front of it and then rewrite the sentece as /mapModel/fleet/hostsRq/response/hosts[windowsPatchesRq[responseStatus='OK'][not(ext:isAnyFromCsv(response/hotfix_id,'KB5004948,KB5005043,KB5005573,KB5006669,KB5007192,KB5008207,KB5009546,KB5010359,KB5011495,KB5012596,KB5013952,KB5014702,KB5014702,KB5015808'))]]/analysisObjectGoId