I'm trying to cycle through a csv and replace any values in a column named Enabled
from True
to A
.
Import-Csv .\test.csv | Where-Object {$_.Enabled -eq 'True'} --> what goes here to replace 'True' with 'A'?
Where-Object
acts like a filter, so the columns that get passed to the rest of the pipeline will only be the ones where Enabled
is True
; which will prevent you from including the others in your output file (I'm assuming you want to have a complete file at the end).
So I would recommend using ForEach-Object
and then modifying based on a condition inside there, but still passing each object through (modified or not):
Import-Csv .\test.csv | ForEach-Object {
if ($_.Enabled -eq 'True') {
$_.Enabled = 'A'
}
$_
} | Export-Csv .\test-modified.csv -NoTypeInformation
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments