I am trying to write a script in power shell to read the first column value in excel, find the value in text file and replace that value with value in second column of the excel file.I am new to the power shell. Please help. Below is the code:
$excel = Import-Csv -Path C:\Users\abc\Desktop\newnbc.csv
foreach ($ex in $excel)
{
$name = $ex.first
$match = Get-Content -Path 'C:\Users\abc\Desktop\all.txt'
foreach ($ma in $match)
{
if ($match | %{$_ -replace $ex.first,$ex.last})
{
((Get-Content -Path C:\Users\abc\Desktop\all.txt -Raw) -replace $name,$ex.last) | Set-Content -Path C:\Users\abc\Desktop\all.txt
}
}
}