Hello Experts,
Below script successfully derives the results found or not-found to out-file(s), but if the csv file contains more than one key it does not out-file the values to third file as duplicates found.
Experts i am newbie and needs your help to modify the script to search recursively for values in csv file and if found create a out-file and append the duplicates in them. So result will be three text files 1. Value found 2.No Value found 3. Duplicate Value found.
Expecting a favourable reply.
$txtFile = Get-Content -Path "C:\alex\txtToReadFrom.txt" | Select-Object -Skip 1
foreach ($line in $txtFile)
{
$txtFileName = $line.Split('|')[1]
$txtValueToCheck = $line.Split('|')[4]
if (!(Test-Path -Path "C:\alex\$txtFileName.csv"))
{
$line | Out-File "C:\alex\txtNoFileOrValueExist.txt" -Append
continue
}
$txtContains = Select-String -Path "C:\alex\$txtFileName.csv" -Pattern $txtValueToCheck
if ($txtContains)
{
Write-Output "txtContains equals: $txtContains"
$fieldAppend = $txtContains.Line.ToString().Split('|')[0, 2] -join '|'
Add-Content "C:\alex\txtForOutput.txt" ($line + $fieldAppend)
}
else
{
$line | Out-File "C:\alex\txtNoFileOrValueExist.txt" -Append
}
}