r/PowerShell•
LUser_

Edit a CSV

Hello r/PowerShell,

I'm trying to create a script that imports a csv and runs it through a while loop looking for Yes or No in column poop. When it finds a No it changes it to a Yes and runs some other code. What I can't figure out is how do I write these changes back to the csv file.

This is the code:

# import the csv containing all the poops
$list = import-csv .\Test.csv

$Poop = $list.Poop

# Step 1.

$i = 0
while ($i -le $Poop.count - 1) {

    if ($Poop[$i] -eq "No") {
       
        Write-Host "NO becomes YES at" $i
        $Poop[$i] = "Yes"
        # Code HERE
        }
    $i++
}

Any help would be appreciated.

Posted Mar 24, 2012, 11:44 PM UTC

43
Loading comments…