Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

CSV Updation

$
0
0

I am new in powershell and working on a script where I have to update the value in CSV using data from the csv itself.

e.g CSV

A,B
100,40
100,33

I want to have "C" column added in CSV which which have values of  "B/A*100"
Output
A,B,C
100,40,40
100,33,33

My Code is below:

$GetCSV= Import-Csv .\test.csv
foreach ($Test in $GetCSV)
{
   $Total = $Test.A
   $Used = $Test.B
$Percentage= $Used/$total*100

$GetCSV | Select-Object *,@{Name='Percentage';Expression={"$Percentage"}} | Export-Csv Output2.csv -NoTypeInformation
}

But it is not giving me the exact result. It just append the last value at every line in CSV.
What I am missing here??


Cheers, Anand Kale | Mumbai,IN. Success is always demanding.. :)


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>