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.. :)