【发布时间】:2022-06-17 23:04:17
【问题描述】:
在这里,我正在尝试创建一个可以读取和写入 CSV 文件的程序。谁能看到我可能出错的地方?在 PowerShell 中运行。
$run = $true
$dataBase = "$PSScriptRoot\Vet.csv"
while ($run -eq $true)
{
Write-Output "1. Add Patient"
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"
}
}
【问题讨论】:
-
如果您告诉我们运行脚本时实际发生的情况(包括您可能收到的任何错误消息),这会容易得多:)
标签: .net powershell csv