I am writing a powershell script that takes in phone numbers stored in a csv file. The csv file has a "taken" field, indicating that the phone number is in use or not. Right now, I have a simple foreach loop that reads in the values of the taken field and changes the no to a yes:
Import-Csv '\\papertransport.com\files\UserDocuments\mneis\Code\phone_numbers2.csv' | ForEach-Object
{
if ($_.taken -eq 'no')
{
$_.taken = 'yes'
break
}
$_
} | Export-Csv \\papertransport.com\files\UserDocuments\mneis\Code\phone_numbers.csv -NoTypeInformation
My question is: how can I get it so the loop stops when when it hits the first no? The break obviously does not work. Also, is it possible to write to the same csv file instead of writing to a second one? When I write to the original it erases all the values inside of it.
foreach($item in Import-Csv ...){}rather than| ForEach-Objectto make thatbreakstatement work