下面是一些示例代码,说明如何使用Switch
语句解决此问题
$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