Here I am trying to create a program that can read and write to a CSV file. Can anyone see where I may be going wrong? Running in PowerShell. The error at the moment is that there seems to be nothing outputting to the CSV. I am trying to be able to append the new $patient to the CSV
$run = $true
$dataBase = "$PSScriptRoot\Vet.csv"
while ($run -eq $true)
{
Write-Output "1. Add Patient"
$choice = Read-Host 'Enter an option (1-5)'
if ($choice -eq '1')
{
$name = Read-Host 'Enter the patient''s name'
$bd = Read-Host "Enter the patient's birthdate (00/00/0000)"
$gender = Read-Host "Male(m)/Female(f)"
(Import-Csv -Path $dataBase -Encoding Default | ForEach-Object{
if($name -eq '')
{
$patient = New-Object PSObject -property @{
Name = $name
Birthdate = $bd
Gender = $gender
}
}
} | ConvertTo-Csv -NoTypeInformation) -replace '"' | Out-File $dataBase
}
else
{
Write-Output "Please enter a valid input"
}
}