I'm trying to find a way to change the value of all the entries in the 'Available Person' column in my csv file using PowerShell.
If the value is 'Y' it should be changed to '1' and if the value is 'N' it should be changed to ')':
Branch Number, CoreID, Available Person, Workstation 8002, FMD354800200, Y, 8002, FMD354800201, Y, 8002, FMD354800202, N, 8002, FMD354800203, N, 8002, FMD354800204, Y,
Here's what I've tried:
$csv=Import-Csv user.csv' | $csv | %{ if($_.'Available Person' -eq "Y") {$_.'Available Person'="1"} } $csv|export-csv user1.csv' -NoTypeInformation
Here is some example code for how you might solve this with a Switch
statement
$ImportedCSV = Import-CSV C:\user.csv
$NewCSV = Foreach ($Entry in $ImportedCsv) {
Switch ($Entry."Available Person") {
Y {$Entry."Available Person" = "1"}
N {$Entry."Available Person" = ")"}
default {Write-Error "$($Entry."Branch Number") has unexpected value for Available Person"}
}
$Entry
}
$NewCSV | Export-CSV C:\user1.csv -NoTypeInformation
try this
(Import-Csv C:\temp\LastAnalyse.csv |
%{$_.'Available Person'=if ($_.Path -eq 'Y') {'1'} elseif ($_.Path -eq 'N') {')'} else {$_.'Available Person'}; $_}) |
Export-Csv C:\temp\LastAnalyse.csv -NoTypeInformation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With